Question about JavaScript Math.random() and basic logic

This basically boils down to a limit and it makes sense. Consider the combinations of numbers between 0 and 10 and count the various differences you can make.

For example, there is one combination with a difference of 9 — (0, 9). There are 5 with a difference of 5:

[0, 5],  
[1, 6], 
[2, 7], 
[3, 8], 
[4, 9]

But there are nine combinations with a difference of 1:

[1, 2], 
[2, 3], 

... 
[8, 9]

With 0 – 10 the counts are:

{1: 9, 2: 8, 3: 7, 4: 6, 5: 5, 6: 4, 7: 3, 8: 2, 9: 1}

There are 45 combinations and the average difference of the those combinations is 3.6666 not 5 because there are more smaller differences than larger ones.

When you increase the granularity from 0 – 10 to 0 – 100 the same pattern holds. There are 99 combinations that result in a difference 1 and only 50 with a difference of 50 for an average of 33.6666.

As you increase the number of significant digits the opposite directions the opposite direction with finer and finer divisions between 0 and 1, you find the same process as the limit approaches 1/3. There are many more smaller difference than larger ones pulling the average difference down. For 0-1 in 0.1 intervals you’ll see 9 with a difference of 0.1 and 5 with a difference of 0.5, at 0.01 there will be 99 with a difference 0.01, and 50 with a difference of 0.5. As the interval approaches 0 the average of the differences approaches 1/3.

Leave a Comment

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)