Pseudo-random number generator

前端 未结 10 759
无人及你
无人及你 2020-12-09 05:17

What is the best way to create the best pseudo-random number generator? (any language works)

10条回答
  •  长情又很酷
    2020-12-09 05:46

    Yikes, that can get VEEEEEERY complicated! There seem to be a number of metrics for how to measure the "randomness" of a random number generator, so it's difficult to meaure which are "best". I would start with Numerical Recipes in C (or whatever langauge you can find one for) for a few examples. I coded up my first simple one from the examples given there.

    EDIT: It's also important to start by determining how complex you need your random number generator to be. I remember a rude awakening I had in C years ago when I discovered that the default random number generator had a period somewhere around 32,767, meaning that it tended to repeat itself periodically after generating that many numbers! If you need a few dice rolls, that's fine. But not when you need to generate millions of "random" values for a simulation.

提交回复
热议问题