开发者

looking for a good random algorithm

开发者 https://www.devze.com 2023-03-16 09:02 出处:网络
I\'m not satisfied with Math.random开发者_StackOverflow社区() from javascript. I would like to create a function that generates random numbers. What I need is that if I generate 100.000 numbers from 1

I'm not satisfied with Math.random开发者_StackOverflow社区() from javascript. I would like to create a function that generates random numbers. What I need is that if I generate 100.000 numbers from 1 to 100, the frequencies that the numbers appear must be as close as possible. The minimum frequency a number appears to be as close as possible to the maximum frequency. Could you give me some ideas?


start with wikipedia, if that doesn't give you any clues I'd recommend Donald Knuths TAOCP Volume 2 - Seminumerical Algorithms, chapter 3


You could probably implement MT19937 in JS, which is a quite capable algorithm suitable for a wide range of applications (not cryptography, though!).

0

精彩评论

暂无评论...
验证码 换一张
取 消