View Full Version : Random number generation
Wolftousen
05-23-2008, 11:07 AM
Ok, so I got tired of waiting for someone to respond on PEQ boards about the melee crit AAs not working properly. I have a 65 berserker and have bought all ranks of crit AAs through PoP, but I don't crit nearly often enough when compared to live.
So, i looked through the server code and low and behold found the problem. It has little to nothing to do with the crit AAs it actually is how random numbers are being generated. Srand and Rand are built into C for convenience and are actually horrible and slow methods to getting random numbers. Very very far from being true random...
I would suggest using this instead:
http://www-personal.umich.edu/~wagnerr/MersenneTwister.html
This is probably causing issues with a lot of other stuff, like the PoP parchment turn ins for spells that give you the same spells over and over b/c it seems like they aren't balanced. It is because of srand/rand...
This should help...
Bulle
05-23-2008, 01:56 PM
There is also the one from the GNU (gsl if my memory is right) which I have integrated in my custom server, through hooks. Supposed to be a "fair" one. It works, though it is hard to tell whether it is better than the original, it has its long streaks of "You miss" too, if you see what I mean...
Wolftousen
05-23-2008, 02:37 PM
Yeah, any number generator is going to have that every once in a while. But srand/rand is just appalling and is not by any means a good way to do it. I have my misses turned off, so i dunno about that. But having a 20% chance to crit and not critting more than maybe 1 time every 20 swings isn't right. I did the etheral parchment turn in maybe 40some times and got the same 3 spells 32 of those times, mostlikely b/c they are on one of the extreme ends of the % chance... Also, mobs on PEQ with a 50/50 drop rate for an item that end up dropping one way more often than the other is another indicator of bad randomization...
jenco420
05-23-2008, 02:54 PM
I'm just being funny, but does'nt EQlive have a horrible RNG? :P
BatCountry
06-03-2008, 07:06 PM
The problem with C's rand() function that's always trumpeted as being a "bad RNG" is not because it doesn't have a fair distribution - it does, when used properly.
The problem with C's rand() function is that it's predictable, so it's unsuitable for cryptography. Your attack rolls do not need to be cryptographically secure. The same RNG is in use in most every computer game you've ever played.
A quick test case run with 5 million iterations generating a number between 1 and 20 using srand(time(NULL)) at the beginning of execution and ((rand()/RAND_MAX)*20+1) shows that each number comes up no more than 0.02% deviation from the appropriate 5% of the time. (This is on a Windows XP platform, using MSVC++ 2005)
The distribution is fair. If it seems like you're critting too infrequently, don't blame the RNG, take a look at the calculations to make sure that all the AAs you think you've got are actually implemented yet.
BatCountry
06-03-2008, 07:13 PM
Incidentally, those 5 million iterations took 2.65 seconds on a 2ghz Athlon XP which is already running EQEmu in the background and Remote Desktop.
vBulletin® v3.8.11, Copyright ©2000-2025, vBulletin Solutions Inc.