Author Topic: Better rng  (Read 18509 times)

Krice

  • (Banned)
  • Rogueliker
  • ***
  • Posts: 2316
  • Karma: +0/-2
    • View Profile
    • Email
Better rng
« 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.

Anvilfolk

  • Rogueliker
  • ***
  • Posts: 374
  • Karma: +0/-0
    • View Profile
Re: Better rng
« Reply #1 on: December 27, 2008, 12:21:43 AM »
I suggest you take a look at the Mersenne Twister. You can find implementations online for sure :)
"Get it hot! Hit it harder!!!"
 - The tutor warcry

One of They Who Are Too Busy

Krice

  • (Banned)
  • Rogueliker
  • ***
  • Posts: 2316
  • Karma: +0/-2
    • View Profile
    • Email
Re: Better rng
« Reply #2 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.

Anvilfolk

  • Rogueliker
  • ***
  • Posts: 374
  • Karma: +0/-0
    • View Profile
Re: Better rng
« Reply #3 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!
"Get it hot! Hit it harder!!!"
 - The tutor warcry

One of They Who Are Too Busy