[Plugin] [REL] MerRandom v2.0 - Mersenne Twister Randoms
#39

Updated to version 2.1 (Can a mod update the title please and thank you) while trying to achieve something I wanted in LSA since starting it, I realized that my method of returning the result from MRandFloatRange could not be used as a true Float value in Pawn. While it worked as it was for random object rotations plugging the variables into MapAndreas however did not work. Thanks to Kye (MapAndreas) I was able to see how to actually pass the value properly. You must now declare your Float variable and use that as the third return parameter.

Some of you may wonder why all the fuss for random float ranges? Well here is some pseudo code....

pawn Код:
new
    Float:x,
    Float:y,
    Float:z;

    MRandFloatRange(408.7256, 2849.402, x); // min and max X coord's
    MRandFloatRange(-1167.788,  -1891.816, y); // min and max Y coord's Creates an area around Los Santos
    MapAndreas_FindZ_For2DCoord(x, y, z); // finds the ground level for the previous X and Y coord.
    somevar = CreatePickup(1212, 2, x, y, z, -1); //Creates a money packet pickup somewhere in Los Santos
In case you didn't catch those comments, when using this plugin and MapAndreas you could have a random coordinate picked in Los Santos and have a money pickup spawned on that coordinates ground level, (MapAndreas limitations apply) tuck that in a loop under OnGameModeInit and you can have 50 random drops....hell you could make yourself a scavenger gamemode if you wanted too....every round pickups in new locations....
[EDIT] An advantage over this method than previous ones is you would have to declare an array of preset locations, which takes time to pick and takes up more memory. Sure they could also just be in the middle of the street which isn't always practical but still it shows its uses....

Speed Test Results:

This is comparing Pawns default random, this plugins MRandom and also MRandFloatRange. MRandFloatRange is slightly slower by about 50ns per call. MRandom is still slightly faster than Pawn (and more random!!)

Код:
[17:40:03] 
random
 -> Average time per call :      144 ns
 -> Total execution time :       72 ms
 -> Calls per second   :  6944444 calls
[17:40:03] 
random
 -> Average time per call :      120 ns
 -> Total execution time :       60 ms
 -> Calls per second   :  8333333 calls
[17:40:04] 
MRandom
 -> Average time per call :      120 ns
 -> Total execution time :       60 ms
 -> Calls per second   :  8333333 calls
[17:40:04] 
MRandom
 -> Average time per call :      116 ns
 -> Total execution time :       58 ms
 -> Calls per second   :  8620689 calls
[17:40:04] 
MRandFloatRange
 -> Average time per call :      170 ns
 -> Total execution time :       85 ms
 -> Calls per second   :  5882353 calls
[17:40:04] 
MRandFloatRange
 -> Average time per call :      162 ns
 -> Total execution time :       81 ms
 -> Calls per second   :  6172839 calls
[17:40:04] 
random
 -> Average time per call :      116 ns
 -> Total execution time :       58 ms
 -> Calls per second   :  8620689 calls
[17:40:04] 
random
 -> Average time per call :      118 ns
 -> Total execution time :       59 ms
 -> Calls per second   :  8474576 calls
[17:40:04] 
MRandom
 -> Average time per call :      112 ns
 -> Total execution time :       56 ms
 -> Calls per second   :  8928571 calls
[17:40:04] 
MRandom
 -> Average time per call :      114 ns
 -> Total execution time :       57 ms
 -> Calls per second   :  8771930 calls
[17:40:04] 
MRandFloatRange
 -> Average time per call :      170 ns
 -> Total execution time :       85 ms
 -> Calls per second   :  5882353 calls
[17:40:04] 
MRandFloatRange
 -> Average time per call :      162 ns
 -> Total execution time :       81 ms
 -> Calls per second   :  6172839 calls
DOWNLOAD: http://forum.sa-mp.com/showthread.ph...037#post462037
Reply


Messages In This Thread
[REL] MerRandom v2.1 - Mersenne Twister Randoms - by cyber_punk - 18.11.2009, 15:48
Re: [REL] MerRandom - Mersenne Twister Randoms - by Google63 - 18.11.2009, 16:42
Re: [REL] MerRandom - Mersenne Twister Randoms - by cyber_punk - 18.11.2009, 16:48
Re: [REL] MerRandom - Mersenne Twister Randoms - by Tannz0rz - 18.11.2009, 18:45
Re: [REL] MerRandom - Mersenne Twister Randoms - by Correlli - 18.11.2009, 18:47
Re: [REL] MerRandom - Mersenne Twister Randoms - by potato - 18.11.2009, 21:39
Re: [REL] MerRandom - Mersenne Twister Randoms - by cyber_punk - 18.11.2009, 22:40
Re: [REL] MerRandom - Mersenne Twister Randoms - by potato - 19.11.2009, 12:17
Re: [REL] MerRandom - Mersenne Twister Randoms - by yom - 19.11.2009, 12:58
Re: [REL] MerRandom - Mersenne Twister Randoms - by Tannz0rz - 19.11.2009, 19:08
Re: [REL] MerRandom - Mersenne Twister Randoms - by MenaceX^ - 19.11.2009, 19:54
Re: [REL] MerRandom - Mersenne Twister Randoms - by Tannz0rz - 19.11.2009, 20:21
Re: [REL] MerRandom - Mersenne Twister Randoms - by yom - 19.11.2009, 20:53
Re: [REL] MerRandom - Mersenne Twister Randoms - by MenaceX^ - 20.11.2009, 12:37
Re: [REL] MerRandom - Mersenne Twister Randoms - by yom - 20.11.2009, 12:39
Re: [REL] MerRandom - Mersenne Twister Randoms - by Woet - 20.11.2009, 12:46
Re: [REL] MerRandom - Mersenne Twister Randoms - by MenaceX^ - 20.11.2009, 12:55
Re: [REL] MerRandom - Mersenne Twister Randoms - by DiDok - 20.11.2009, 13:52
Re: [REL] MerRandom - Mersenne Twister Randoms - by cyber_punk - 20.11.2009, 18:12
Re: [REL] MerRandom - Mersenne Twister Randoms - by potato - 20.11.2009, 20:16
Re: [REL] MerRandom - Mersenne Twister Randoms - by cyber_punk - 21.11.2009, 02:45
Re: [REL] MerRandom - Mersenne Twister Randoms - by potato - 21.11.2009, 12:31
Re: [REL] MerRandom - Mersenne Twister Randoms - by cyber_punk - 21.11.2009, 12:55
Re: [REL] MerRandom - Mersenne Twister Randoms - by DiDok - 21.11.2009, 14:40
Re: [REL] MerRandom - Mersenne Twister Randoms - by DiDok - 26.11.2009, 14:19
Re: [REL] MerRandom - Mersenne Twister Randoms - by Destrojer - 26.11.2009, 15:31
Re: [REL] MerRandom - Mersenne Twister Randoms - by Google63 - 01.12.2009, 16:50
Re: [REL] MerRandom - Mersenne Twister Randoms - by MJ! - 11.12.2009, 17:55
Re: [REL] MerRandom - Mersenne Twister Randoms - by Correlli - 11.12.2009, 18:03
Re: [REL] MerRandom - Mersenne Twister Randoms - by Tannz0rz - 11.12.2009, 18:04
Re: [REL] MerRandom - Mersenne Twister Randoms - by MJ! - 11.12.2009, 18:38
Re: [REL] MerRandom - Mersenne Twister Randoms - by cyber_punk - 30.08.2010, 12:10
Re: [REL] MerRandom - Mersenne Twister Randoms - by wups - 05.09.2010, 12:09
Re: [REL] MerRandom - Mersenne Twister Randoms - by cyber_punk - 05.09.2010, 14:35
Re: [REL] MerRandom v2.0 - Mersenne Twister Randoms - by nemesis- - 07.09.2010, 03:18
Re: [REL] MerRandom v2.0 - Mersenne Twister Randoms - by cyber_punk - 07.09.2010, 13:49
Re: [REL] MerRandom v2.0 - Mersenne Twister Randoms - by nemesis- - 07.09.2010, 14:28
Respuesta: [REL] MerRandom v2.0 - Mersenne Twister Randoms - by xenowort - 07.09.2010, 17:43
Re: [REL] MerRandom v2.0 - Mersenne Twister Randoms - by cyber_punk - 26.09.2010, 23:01
Re: [REL] MerRandom v2.0 - Mersenne Twister Randoms - by cyber_punk - 27.10.2010, 20:52
Re: [REL] MerRandom v2.0 - Mersenne Twister Randoms - by MisterTickle - 22.09.2011, 08:53
Re: [REL] MerRandom v2.0 - Mersenne Twister Randoms - by [L3th4l] - 22.09.2011, 09:22
Re: [REL] MerRandom v2.0 - Mersenne Twister Randoms - by aRoach - 22.09.2011, 12:36
Re: [REL] MerRandom v2.0 - Mersenne Twister Randoms - by cyber_punk - 22.09.2011, 17:01
Re: [REL] MerRandom v2.0 - Mersenne Twister Randoms - by Edvin - 22.09.2011, 18:43
Re: [REL] MerRandom v2.0 - Mersenne Twister Randoms - by Kyle - 27.06.2012, 10:59
Respuesta: [REL] MerRandom v2.0 - Mersenne Twister Randoms - by Siralos - 15.08.2012, 15:23

Forum Jump:


Users browsing this thread: 2 Guest(s)