victorqribeiro / googol

Googol Game or "You should learn when to quit". A JavaScript game.

Home Page:https://victorribeiro.com/googolGame

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

getRandomBigNumber Isn't Evenly Distributed

thisBrian opened this issue · comments

Appreciate the project; something to take note:

The length of digits generated via
const r = Math.floor(Math.random() * 101);
is not evenly distributed.

Consider a number with a max of 2 digits (instead of a googol).
Numbers 0-9 will have a 50% chance to be chosen as would numbers 10-99.

A solution would be to always generate a fixed length of digits, then remove any preceding zeros.

Link to HN Discussion

Is kind hard for me to even calculate the probabilities of such large numbers, but, in order for me to get a number with, lets say 10 decimal places using your proposed solution, I would have to get 90 consecutive leading zeros. Seems to me that would never happen.