3 ms·
>"The implementation first chooses the length of the number, then fills in the digits. This makes it biased towards smaller numbers." Why?
by atum47 7y ago
>"The implementation first chooses the length of the number, then fills in the digits. This makes it biased towards smaller numbers."
Why?
- bentona 7y agoSemi-relevant: https://en.wikipedia.org/wiki/Benford%27s_law https://en.wikipedia.org/wiki/Benford%27s_law
- atum47 7y agoDamn...
- atum47 7y agoPeople, I just ran this simple script on my terminal using Node and I got a pretty uniform result. a = {} for(let i = 0; i < 100000; i++){ let n = Math.floor(Math.random() * 10); if( n in a ) a[n] += 1 else a[n] = 1 } My result: { '0': 9917, '1': 10015, '2': 9957, '3': 10107, '4': 10019, '5': 10037, '6': 10120, '7': 9914, '8': 10042, '9': 9872 }
- fourthark 7y agoSure but that’s not the algorithm you used in the repo.
- peteretep 7y ago> real-life sets of numerical data Today you learned: Node’s random number generator isn’t selecting from a real-life set of numerical data
- atum47 7y agoyeah, I just mixed two informations. I thought the other person said my algorithm would be biased towards small numbers cause I use the JS random function to pick the number of decimal places for the number
- bentona 7y agoYep, sorry, didn't mean to say this directly applied, just a neat concept that's somewhat related.
- jbay808 7y agoAlso relevant (and in my mind, the underlying explanation for Benford's Law): https://en.m.wikipedia.org/wiki/Jeffreys_prior https://en.m.wikipedia.org/wiki/Jeffreys_prior
- bentona 7y agoJust getting into bayesian inference and this sent me down a rabbit hole, thanks :)
- fourthark 7y agoConsider a two digit number. With this algorithm, half of the numbers generated will be less than 10, and half will be 11-99. Likewise with the full 100 digits this algorithm has a 1% chance of generating a number less than 10, while the correct proportion would be 1e-100. The algorithm also does not generate numbers with zero in them (presumably to avoid leading zeroes, but this will skew results somewhat). I think the correct algorithm would be to generate 100 digits and then remove the leading zeroes.