We were introduced to the standard C
rand() function, and how to use it.
At some point during the class we were asked how to roll a die. The simple answer was to create a random number, take its modulo 6, and add 1.
rand()%6 + 1
However, the right answer was building a function that returns a value in the range [0,1) and then operating with that function to get a random number between 1 and 6.
Since most people in my class haven't seen probability yet, we weren't told why this was the right answer, but the class's assistant told us that taking the modulo of the random number produces a normal distribution of the numbers, while the other function we built:
rand / ((double) RAND_MAX + 1)
produces a uniform distribution.
Could anyone explain why this happens? I'm not a CS student myself so my knowledge is very basic
Thanks in advance.