Generate random value with a distance between them

However, sometimes, the random numbers are almost the same (e.g. 591 and 595)

Random numbers should be random, and that will happen. They can even be equal! If you make a rule about a "distance between them" they will not be random.

But post the code, following forum rules.