Sign in

At least write a line of code before going to bed every day


The old way to get random numbers is with srand(time (NULL)) function for initialization, rand() to get the random number, and rand() % maxValue to get a random number between 0 and maxValue. But after I watched Stephan T. Lavavej’s statements on this video, the usage of simple rand() plus modulus paradigm was considered harmful and terrible. Why?

According to C++ documentation of rand(), you’ll see this..

Now, see the documentation of RAND_MAX and you will see this..

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store