dimanche 28 décembre 2014

C why is their a probability of higher numbers using rand() [duplicate]


Weird question I guess. Its out of curiosity.


Using rand() function, if we set the parameters between 1-10, i then ran a test a few times on a my machines UNIX operating system, more specifically Ubuntu. My results always showed higher numbers (greater then 5) being more likely returned. It didn't seem at all as if it was random.


I also read up on the module which states that using the modules operation, we form some kind of bias.



Notice though that this modulo operation does not generate uniformly distributed random numbers in the span (since in most cases this operation makes lower numbers slightly more likely).


Why is that? Also it said lower numbers become more likely, however i get more higher numbers





Aucun commentaire:

Enregistrer un commentaire