Search code examples
crandomimplementationmersenne-twister

Need help converting C Mersenne twister implementation to be useful to me


I am using this implementation of the Mersenne twister for a diamond-square terrain generator I am writing. The point of using a separate implementation rather than the built in rand() is that I want the same seed to generate the same map every time. Diamond-square requires a random error to be added on to every pixel, so I need to generate many, many random numbers from a single seed. Mersenne twister would be good for this, but as far as I can tell, this implementation generates only one random number. I have replaced the rand() in mt_init() with an integer argument. I can make no further head or tail of the code, however, so I must turn to you to ask: what steps should I take so that mt_random(n) returns the nth random number in the Mersenne twister series it belts out?


Solution

  • If you need more random numbers, just keep calling mt_random as many times as you want.