# Random number generation in MATLAB with condition

How can I generate random numbers in MATLAB with the condition that each new number has a minimum difference with all previously generated numbers for that matrix. So, X = rand(1,20) would generate 20 random numbers between 0 and 1, but how do I add the condition that each newly generated random number of those 20 has at least a difference of 0.05 with any previously generated number in that sequence of 20. Thanks

This is a standard way of generating uniform random numbers on a non-standard domain. For instance, it is used in Java's Gaussian rng (based on the polar method) which starts with a random uniformly distributed point in the unit disc. Java constructs a random point in the square $[-1,1]\times[-1,1]$, and tries again and again until it is closer than $1$ to the origin.