Pseudo-random number generator

前端 未结 10 758
无人及你
无人及你 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:51

    It all depends on the application. The generator that creates the "most random" numbers might not be the fastest or most memory-efficient one, for example.

    The Mersenne Twister algorithm is a popular, fairly fast pseudo-random number generator that produces quite good results. It has a humongously large period, but also a relatively humongous state (2.5 kB). However it is not deemed good enough for cryptographic applications.

    Update: Since this answer was written, the PCG family of algorithms was published that seems to outperform existing non-cryptographic algorithms on most fronts (speed, memory, randomness and period), making it an excellent all-round choice for anything but cryptography.

    If you're doing crypto though, my answer remains: don't roll your own.

提交回复
热议问题