I have a function that generates a random number
int randomNumber(int l, int u)
//get random number between l and u----------
unsigned seed = chrono::system_clock::now().time_since_epoch().count();
default_random_engine generator (seed);
My problem is, because of the seed, calling the function twice in a row happens so fast it returns the same result. If I call the function constantly I get the same result 15 or 16 times in a row.
When I need to get different random numbers quickly are there certain ways this is usually approached?
My first thought is to get a random number from 100-999 if I need 3 random single digit numbers and then just take the 1st, 2nd, and 3rd digits. The only problem is I have to know how many times the function will be called at once and for what I'm trying to do I can't know if t will be called 3 times or 20 times in rapid succession.
I could create a vector of 20 or so ints and fill it with random 10 digit numbers generated once every second. Once the vector is full the generator stops. If I need a random number I take the first element of the vector, use the % operator to get a number in the desired range, and then erase the first element.
It's not pretty but it would work....I think. I would till love to hear some better suggestions.