Generate random value with a distance between them

If you do it wrong you can get stuck in a loop for some time.