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

Introduction

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?

Returns a pseudo-random integral value between ​0​ and RAND_MAX (0 and RAND_MAX included)

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

This value is implementation dependent. …

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