Random() always returns the same value

A look at the reference for the random() function may shed some light on your problem.

If it is important for a sequence of values generated by random() to differ, on subsequent executions of a sketch, use [url=https://www.arduino.cc/reference/en/language/functions/random-numbers/randomseed/]randomSeed()[/url] to initialize the random number generator with a fairly random input, such as analogRead() on an unconnected pin.