The trick "rand() % n" may not fit the uniform distribution requirement as lower numbers are more likely to be picked by this operation, according to this post:
Then which function can truly generate the random numbers within a range in C++? I am not sure if std::uniform_int_distribution can do the job (http://www.cplusplus.com/reference/random/uniform_int_distribution/)...Suggestions are welcomed :)
The closest true random number I have heard of is the Atmospheric Noise Random Generator, https://www.random.org/
You can try using std::random_device. Also, instead of using %, you can use division:
int randInt = low + (rand()*(hi - low)) / RAND_MAX
if you are worried about some of the lower values being less than 0.01% more likely of being chosen
Looks like your connection to LeetCode Discuss was lost, please wait while we try to reconnect.