Replies: 1 comment
-
Also take in consideration that all that numbers are not truly random, specially on the deterministic context of blockchains having real random numbers is really important. |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
What is a modulo bias when using a random number generator like in lesson 7?
While studying lesson 7 I wondered, if it is such a great idea to calculate the winner with the modulo technique. I am referring to this part of the course 07:01:30.
int value = rand() % range;
This is a common technique for generating random numbers in a particular range, however, according to the article below it almost always introduces some bias that causes the distribution to stop being uniform.
The following article is explaining why this would actually not be a fair lottery and describes a case with 20.000 possible winners. Every number between 0 and 12767 is twice as likely to be drawn as every number from 12768 to 19999; this is a massive bias.
How much bias is introduced by the remainder technique?
Correction for modulo bias
This article here by David Egan is describing a way to overcome this problem and it even has a nice python example in it.
Pseudo Random Numbers in a Range and Modulo Bias
Beta Was this translation helpful? Give feedback.
All reactions