Better random algorithm?

后端 未结 14 1786
情书的邮戳
情书的邮戳 2020-12-16 06:48

I\'m making a game in C++ and it involves filling tiles with random booleans (either yes or no) whether it is yes or no is decided by rand() % 1. It doesn\'t fe

14条回答
  •  借酒劲吻你
    2020-12-16 07:29

    I have used the Mersenne Twister random number generator successfully for many years. Its source code is available from the maths department of Hiroshima Uni here. (Direct link so you don't have to read Japanese!)

    What is great about this algorithm is that:

    1. Its 'randomness' is very good
    2. Its state vector is a vector of unsigned ints and an index, so it is very easy to save its state, reload its state, and resume a pseudo-random process from where it left off.

    I'd recommend giving it a look for your game.

提交回复
热议问题