Generate random value with a distance between them

Remember the previous number, check the new against the previous, if not big enough difference take a new random number.