alliedmodders / amxmodx

AMX Mod X - Half-Life 1 Scripting and Administration
http://www.amxmodx.org/
496 stars 200 forks source link

Feature Request: Better Random Number Generators #545

Open PartialCloning opened 6 years ago

PartialCloning commented 6 years ago

The current random number generators are not that random.

  1. random.
  2. random_num (Using the engine's RandomLong).

I have no data to back that claim but I'm not the only person to notice a pattern. A forum search shows many posts making the same claim.

In 2005, "Twilight Suzuka" released a better random number generator for AMXMODX, Module: RandomX using the Mersenne Twister PRNG.

RandomX uses a random number generator called the "Mersenne Twister", which is one of the fastest random number generators availible, and is light years ahead of the current ones implimented in AMXx. This means high quality and inexpensive randomized variables.

In 2009 "altex" reported a bug in the random number generator used in Sourcemod (Bug #3831). Mersenne Twister PRNG based random number generators GetURandomInt and GetURandomFloat were then added to SourceMod. Commit: Added better random number generator.

Possible Solutions:

ClaudiuHKS commented 6 years ago

Tested Mersenne Twister (std::mt19937)

INT = -13, 0, 13, -7, 10, 6, -9, -14, 9, -11, -8, -5, 0, 7, 10, 10 REAL = -9.73, 10.94, -15.11, -14.70, -13.85, -3.49, -5.18, 2.96, -9.95, 4.09, 13.67, 3.87, -6.42, -6.23, -7.89, -6.28

So Mersenne Twister isn't much more better in my opinion.

rsKliPPy commented 6 years ago

Repeating numbers aren't a sign of a bad algorithm, that's not how random number generators are tested.

ClaudiuHKS commented 6 years ago

I'm not searching for some algorithm that isn't repeating numbers.

I know that M.T. method is better but the differences aren't huge though.

Besides, I would definetely agree implementing M.T. into AMXX.

WPMGPRoSToTeMa commented 6 years ago

random_num(0, 255): random_num(0, 255) random_num(0, 1): random_num(0, 1) random(256): random(256) random(2): random(2)

justgo97 commented 6 years ago

You can try what HamletEagle suggested to try the RandomX module https://forums.alliedmods.net/showpost.php?p=2613505&postcount=11

ClaudiuHKS commented 6 years ago

AMXX can also add SM's M.T. generator but I strongly recommend that random, random_num and random_float functions will be the same as they actualy are.

WPMGPRoSToTeMa commented 6 years ago

@ClaudiuHKS as you can see from pictures random isn't so good.

ClaudiuHKS commented 6 years ago

Oh my.. I've always thought that..

#define random( x ) random_num ( 0, x )

You're right..

IgnacioFDM commented 6 years ago

It's probably best to just add a new function for a CSPRNG

WPMGPRoSToTeMa commented 6 years ago

@ClaudiuHKS

#define random( x ) random_num ( 0, x )

#define random( x ) random_num ( 0, ( x ) - 1 ) of course.

PartialCloning commented 6 years ago

@WPMGPRoSToTeMa can you post a picture showing how different RandomX's or SourceMod's PRNG looks? Do you think such a feature is needed or is random_num good enough?

WPMGPRoSToTeMa commented 6 years ago

@PartialCloning I think picture is only a minimal test, we need to make additional tests.

toorisrael commented 2 years ago

If you do something like this (just an example): public void OnMapStart() { for(int i = 1; i <= 3; fake++) { LogMessage("%i", GetRandomInt(0, 148)); } } and just keep restarting server, it will almost always log the same 3 numbers. (I've tested this only on one server). EDIT: sorry, now I see it's amx topic.

Maxi605 commented 1 year ago

Will this ever be addressed?