+ 1
Challenge: Random number generator based on an parameter from 0-100 that reprezents the chance to output a bolean 0 or 1
any language and i sugest making it a function or a method witf a parameter int chance and the return type of bool ex random(40) would have a 40% chance to output 1 and 60% chance to output 0 bonus chalenge: try to make it work wih float values as parameter
5 Answers
+ 13
Here's my C# implementation! ā
I decided to give it a try after having a little talk of randomness with CalviÕ². Just increase the number of toss to observe the Law of Large Number in action. Enjoy~ ā¤
https://code.sololearn.com/cXuX2eYWTVPs/?ref=app
+ 3
Shouldn't be too hard (in js, anyway :P)
https://code.sololearn.com/WODUzBdruUzk/?ref=app
Returns true and false, if you really need either 1 or 0 you can convert it with Number(rand(50))
+ 2
We would always get 50/50 for testing above 1 million Boolean numbers
https://code.sololearn.com/WSCT2fF3mF49/?ref=app
+ 2
Work-in-progress
This demonstrates a 60/40 bias produced by using a modulus that does not evenly divide RAND_MAX, a problem for c++ .
I'm working on a way to choose the split, for now I want to show the effect of the bias in this relevant context. (not showing 100 yet because of lag; will try to address that)
Reference:
https://stackoverflow.com/questions/10984974/why-do-people-say-there-is-modulo-bias-when-using-a-random-number-generator
https://code.sololearn.com/WmOmcQ9HYcDR/?ref=app