Temple of The Roguelike Forums

Development => Programming => Topic started by: Krice on December 26, 2008, 05:20:50 PM

Title: Better rng
Post by: Krice on December 26, 2008, 05:20:50 PM
I heard rand() is not that good and there are better alternatives. What should I use? I want it to be free from any license nonsense. Also, how to make an accurate percentage hit? I think there is a flaw in my percentage random routine, because it's hitting even 2% quite often.
Title: Re: Better rng
Post by: Anvilfolk on December 27, 2008, 12:21:43 AM
I suggest you take a look at the Mersenne Twister (http://en.wikipedia.org/wiki/Mersenne_twister). You can find implementations online for sure :)
Title: Re: Better rng
Post by: Krice on December 27, 2008, 09:50:11 AM
The C++ source code for MT looks like poop, but I may have to give up quality standards in this case and use it. I don't know the theory to implement one myself. I'm hopeless in math.
Title: Re: Better rng
Post by: Anvilfolk on December 27, 2008, 08:02:18 PM
Heheh, I know. Just treat it like an ordinary lib... make a simple .h file and only import the randomization function.

And the Mersenne Twister generates numbers in a Uniform distribution - there are ways you can transform that into other distributions, like Normal, Poisson, Exponencial, etc. I had that in a math course this semestre, it's pretty cool, and not that hard!