Uniform distribution of integers using floating point source

后端 未结 5 565
渐次进展
渐次进展 2021-01-06 00:23

The standard way to get a random integer in the range [0, n) in JavaScript - or any other language that only offers a random() function that returns a float in the range [0,

5条回答
  •  南笙
    南笙 (楼主)
    2021-01-06 01:06

    According to http://es5.github.io/x15.8.html#x15.8.2.14

    the functionality of Math.random

    Returns a Number value with positive sign, greater than or equal to 0 but less than 1, chosen randomly or pseudo randomly with approximately uniform distribution over that range, using an implementation-dependent algorithm or strategy. This function takes no arguments.

    check out this post: https://stats.stackexchange.com/questions/40384/fake-uniform-random-numbers-more-evenly-distributed-than-true-uniform-data

    this has become above my head, sorry i have nothing left to contribute

提交回复
热议问题