Hey, is there way to choose evenly distributed random numbers? I used this function
Math.floor(Math.random()*2)
which returns either 1 or 0. However, I dont think it has exact 50% chance to produce either one. Better thoughts? Thank you
If you do not believe, check:
<script type="text/javascript">
var total = 0;
var ones = 0;
for (var i = 0; i < 100000; i++, total++) {
ones += Math.floor(Math.random()*2);
}
alert(ones/total);
</script>
This code gives me 0.49972 - very close to 50%.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With