How can I distort the distribution of a set of random numbers?

ぐ巨炮叔叔 提交于 2019-12-22 18:36:33

问题


I want to craft an algorithm that will give me numbers that are random in the sense that I have no idea what they'll be, but at the same time, numbers that are closer to 0 have to be more likely to occur as output while those closer to 1 must be less likely. I'd like to play around with both linear and exponential distributions, so please give at least hints for implementing both.

I've thought and thought about how to approach this issue, but I still don't even have a clue, so any pointers would be appreciated.

NOTE: I'm not looking to discuss, nor do I yet understand, the intricacies of "true" vs. "pseudo" randomness... This has nothing to do with security or cryptography, and for it I'll simply be using Javascript's Math.random() as a seed, just so we're all clear about what I'm asking.


回答1:


var random = Math.pow(Math.random(), 2);



回答2:


Take a look at Poisson distribution, probably you can use it for your own purposes, essentially a poisson distribution is not deterministic, but it has a certain frequency of occurrence: wikipedia has a good introductory info about this: http://en.wikipedia.org/wiki/Poisson_distribution

Algorithm:

algorithm poisson random number (Knuth):
init:
     Let L ← e−λ, k ← 0 and p ← 1.
do:
     k ← k + 1.
     Generate uniform random number u in [0,1] and let p ← p × u.
while p > L.
return k − 1.


来源:https://stackoverflow.com/questions/13451236/how-can-i-distort-the-distribution-of-a-set-of-random-numbers

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!