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

Quote:
Originally Posted by potato
It still doesn't seem to be compiling right:

Code:
gcc -c -O3 -w -DLINUX -I../SDK/amx/ ../SDK/amx/*.c
g++ -c -O3 -w -DLINUX -I../SDK/amx/ ../SDK/*.cpp
g++ -c -O3 -w -DLINUX -I../SDK/amx/ *.cpp
g++ -O2 -fshort-wchar -shared -o "./Release-Linux/merrandom.so" *.o
collect2: ld terminated with signal 11 [Segmentation fault]
merrandom.o: In function `Supports':
merrandom.cpp:(.text+0x0): multiple definition of `Supports'
helloworld.o:helloworld.cpp:(.text+0x0): first defined here
merrandom.o: In function `Load':
merrandom.cpp:(.text+0x10): multiple definition of `Load'
helloworld.o:helloworld.cpp:(.text+0x10): first defined here
merrandom.o:(.bss+0x0): multiple definition of `logprintf'
helloworld.o:(.bss+0x0): first defined here
/usr/lib/gcc/i486-pc-linux-gnu/4.2.4/../../../../i486-pc-linux-gnu/bin/ld: Warning: size of symbol `logprintf' changed from 8 in helloworld.o to 4 in merrandom.o
merrandom.o: In function `Unload':
merrandom.cpp:(.text+0x40): multiple definition of `Unload'
helloworld.o:helloworld.cpp:(.text+0x50): first defined here
merrandom.o: In function `AmxUnload':
merrandom.cpp:(.text+0x60): multiple definition of `AmxUnload'
helloworld.o:helloworld.cpp:(.text+0x70): first defined here
merrandom.o: In function `AmxLoad':
merrandom.cpp:(.text+0xd0): multiple definition of `AmxLoad'
helloworld.o:helloworld.cpp:(.text+0x190): first defined here
merrandom.o:(.bss+0x4): multiple definition of `ppPluginData'
helloworld.o:(.bss+0x8): first defined here
/usr/lib/gcc/i486-pc-linux-gnu/4.2.4/../../../../i486-pc-linux-gnu/bin/ld: Warning: size of symbol `ppPluginData' changed from 8 in helloworld.o to 4 in merrandom.o
/usr/lib/gcc/i486-pc-linux-gnu/4.2.4/../../../../i486-pc-linux-gnu/bin/ld: i386:x86-64 architecture of input file `helloworld.o' is incompatible with i386 output
/usr/lib/gcc/i486-pc-linux-gnu/4.2.4/../../../../i486-pc-linux-gnu/bin/ld: i386:x86-64 architecture of input file `invoke.o' is incompatible with i386 output
make: *** [all] Error 1
P.S. it's a Gentoo.
Have you redownloaded the package off of the first page? If you have delete the old folder and only use the clean one, you should not have any messages about helloworld.o or invoke.o I no longer have those files in the package as they are unneeded. The problem with getting it to compile was simply from not deleting the old files no longer needed and generating a fresh .o (object file) once that was done I had no problems compiling.

So please delete the old package and download the one that;s on the first page it will compile. Please let me know if it does if not I will try to find a Gentoo to compile from.
Reply
#22

When I deleted all object files then I was able to compile it.
Thanks!
Reply
#23

Quote:
Originally Posted by potato
When I deleted all object files then I was able to compile it.
Thanks!
Glad you got it working, enjoy a better random
Reply
#24

I'm currently testing it, looks A LITTLE better, when I'll be bored I'll maybe make comparison using statistical tests (<3 stats ^^) to see if it's better or not
Reply
#25

BUMP, found some bug/inconvinience: due to changed parameter you can't use MRandom(sizeof(array)) because it could return integer that doesn't fit in array (array[2], MRandom(sizeof(array)) returns 2, but array has only 0 and 1...). Remember to use sizeof()-1
Reply
#26

I thing you don't know for what we use sizeof. Sizeof "return" arry size. For example if we have
pawn Code:
new
  arry[10],
  arry2[15],
  arry3[2];
sizeof "return" 10, 15, 2. Now i don't know how to say that in english, but i can show you that what i want say.
pawn Code:
enum 10
{
    0,
    1,
    2,
    3,
    4,
    5,
    6,
    7,
    8,
    9
}
enum 15
{
    0,
    1,
    2,
    3,
    4,
    5,
    6,
    7,
    8,
    9,
    10,
    11,
    12,
    13,
    14
}
enum 2
{
    0,
    1
}
You have never used sizeof() - 1 becouse your result could be wrong.

Sorry for my language but i still working

//Edit

random returns only numbers in range 0 - (max - 1)
Reply
#27

Quote:
Originally Posted by DiDok
BUMP, found some bug/inconvinience: due to changed parameter you can't use MRandom(sizeof(array)) because it could return integer that doesn't fit in array (array[2], MRandom(sizeof(array)) returns 2, but array has only 0 and 1...). Remember to use sizeof()-1
See for yourself: http://msdn.microsoft.com/en-us/library/4s7x1k91.aspx, scroll to bottom of article.
Reply
#28

Where's the source ?
Reply
#29

Quote:
Originally Posted by Щә яә Ґя
Where's the source ?
There's a link in the first post.
Reply
#30

Quote:
Originally Posted by Щә яә Ґя
Where's the source ?
...In the zipped file?
Reply
#31

Oh , ma bad. It was a problem from WinRar
Reply
#32

New version released, now much much faster.


Speed test done on a Dual Core AMD running @ 3.0Ghz with 800MHz frontside bus.

Код:
[13:21:59] 
random
 -> Average time per call :      102 ns
 -> Total execution time :       51 ms
 -> Calls per second   :  9803922 calls
[13:21:59] 
random
 -> Average time per call :      102 ns
 -> Total execution time :       51 ms
 -> Calls per second   :  9803922 calls
[13:21:59] 
MRandom
 -> Average time per call :      100 ns
 -> Total execution time :       50 ms
 -> Calls per second   : 10000000 calls
[13:21:59] 
MRandom
 -> Average time per call :       96 ns
 -> Total execution time :       48 ms
 -> Calls per second   : 10416667 calls
[13:21:59] 
random
 -> Average time per call :      104 ns
 -> Total execution time :       52 ms
 -> Calls per second   :  9615385 calls
[13:21:59] 
random
 -> Average time per call :      102 ns
 -> Total execution time :       51 ms
 -> Calls per second   :  9803922 calls
[13:22:00] 
MRandom
 -> Average time per call :       98 ns
 -> Total execution time :       49 ms
 -> Calls per second   : 10204082 calls
[13:22:00] 
MRandom
 -> Average time per call :       96 ns
 -> Total execution time :       48 ms
 -> Calls per second   : 10416667 calls
[05:17:50] 
random
 -> Average time per call :      112 ns
 -> Total execution time :       56 ms
 -> Calls per second   :  8928571 calls
[05:17:50] 
random
 -> Average time per call :      122 ns
 -> Total execution time :       61 ms
 -> Calls per second   :  8196721 calls
[05:17:50] 
MRandom
 -> Average time per call :      100 ns
 -> Total execution time :       50 ms
 -> Calls per second   : 10000000 calls
[05:17:50] 
MRandom
 -> Average time per call :      108 ns
 -> Total execution time :       54 ms
 -> Calls per second   :  9259259 calls
[05:17:50] 
random
 -> Average time per call :      112 ns
 -> Total execution time :       56 ms
 -> Calls per second   :  8928571 calls
[05:17:50] 
random
 -> Average time per call :      106 ns
 -> Total execution time :       53 ms
 -> Calls per second   :  9433962 calls
[05:17:50] 
MRandom
 -> Average time per call :       98 ns
 -> Total execution time :       49 ms
 -> Calls per second   : 10204082 calls
[05:17:50] 
MRandom
 -> Average time per call :      100 ns
 -> Total execution time :       50 ms
 -> Calls per second   : 10000000 calls
[06:48:44] 
random
 -> Average time per call :      104 ns
 -> Total execution time :       52 ms
 -> Calls per second   :  9615385 calls
[06:48:44] 
random
 -> Average time per call :      108 ns
 -> Total execution time :       54 ms
 -> Calls per second   :  9259259 calls
[06:48:44] 
MRandom
 -> Average time per call :      100 ns
 -> Total execution time :       50 ms
 -> Calls per second   : 10000000 calls
[06:48:44] 
MRandom
 -> Average time per call :       98 ns
 -> Total execution time :       49 ms
 -> Calls per second   : 10204082 calls
[06:48:44] 
random
 -> Average time per call :      106 ns
 -> Total execution time :       53 ms
 -> Calls per second   :  9433962 calls
[06:48:44] 
random
 -> Average time per call :      106 ns
 -> Total execution time :       53 ms
 -> Calls per second   :  9433962 calls
[06:48:45] 
MRandom
 -> Average time per call :       98 ns
 -> Total execution time :       49 ms
 -> Calls per second   : 10204082 calls
[06:48:45] 
MRandom
 -> Average time per call :      102 ns
 -> Total execution time :       51 ms
 -> Calls per second   :  9803922 calls
[EDIT] New version on first post...
Reply
#33

Now it's nice!
Reply
#34

Quote:
Originally Posted by wups
Посмотреть сообщение
Now it's nice!
Thanks.




Offtopic(ish):

Can I a mod to change the title to..... MerRandom v2.0 - Mersenne Twister Randoms

[EDIT] Thanks to whomever changed it.
Reply
#35

I compiled the linux version and gave it a go.. seems to work well. It would be nice if the native random() worked this well.
Reply
#36

Quote:
Originally Posted by nemesis-
Посмотреть сообщение
I compiled the linux version and gave it a go.. seems to work well. It would be nice if the native random() worked this well.
I agree the default pawn random is nothing compared to this algorithm. I love when people ask me why I even made this, it makes me wonder if they every really used the pawn random. I know I use it very often on my game mode and it shows especially to players that play on a daily basis.


Unfortunately I did miss a couple bugs the first time around. :S Its highly recommend to download this version.

http://www.sendspace.com/file/j7en2j
(First post link also updated)


Fixed: MRandom not behaving like the default PAWN random i.e MRandom(2) now returns 0,1 not 0,1,2 (sorry if people started changing there scripts I really wanted that fixed before release.....it just slipped my mind)

Fixed: MRandRange was returning garbage/not working this is fixed.

NOTE: An added note while I was doing some extra testing I found out if you do MRandFloatRange(1.0, max) you could possibly end up with a float value less than 1.0 an easy work around for this is to pad it with a few more decimal places i.e MRandFloatRange(1.0000, max) will not dip below 1.0 (at least it didn't in several hundred calls)
Reply
#37

Quote:
Originally Posted by cyber_punk
Посмотреть сообщение
I agree the default pawn random is nothing compared to this algorithm. I love when people ask me why I even made this, it makes me wonder if they every really used the pawn random. I know I use it very often on my game mode and it shows especially to players that play on a daily basis.
Having used pawn's native random() I can vouch that it isn't THAT random. I've seen it re-use the same number in back-to-back sequences far too many times.


Quote:

Unfortunately I did miss a couple bugs the first time around. :S Its highly recommend to download this version.

http://www.sendspace.com/file/j7en2j
(First post link also updated)


Fixed: MRandom not behaving like the default PAWN random i.e MRandom(2) now returns 0,1 not 0,1,2 (sorry if people started changing there scripts I really wanted that fixed before release.....it just slipped my mind)

Fixed: MRandRange was returning garbage/not working this is fixed.

NOTE: An added note while I was doing some extra testing I found out if you do MRandFloatRange(1.0, max) you could possibly end up with a float value less than 1.0 an easy work around for this is to pad it with a few more decimal places i.e MRandFloatRange(1.0000, max) will not dip below 1.0 (at least it didn't in several hundred calls)

The only function I tested/used was MRandom().. didn't try the others. It is a good plugin though until I need such a true level of randomness I'm probably going to defer to the native random().
Reply
#38

Great man!!! exelent!
Reply
#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
#40

Quote:
Originally Posted by ******
Посмотреть сообщение
Why can't you just do:

Код:
	return amx_ftoc(seed);
That way people can just do:

pawn Код:
new Float:rand = MRandFloatRange(10, 90);
I had originally tried that in version 2.0 yet it refused to work properly in pawn I would end up with a rather long integer instead when declaring it as a float and it would only return a float when declared as an int (go figure) which is why I had to change it as I needed it to be a float in pawn. It just caused me to scratch my head I thought just returning amx_ftoc would have worked.....


Quote:
Originally Posted by ******
Посмотреть сообщение
Also, you have many files in the download which don't need to be included and will greatly reduce the size:
  • HelloWorld.vcproj.Giga-PC.Giga.user
  • HelloWorld.vcproj.User-PC.User.user
  • MerRandom.ncb
  • MerRandom.suo (hidden file)
  • .o and .a files
  • The .lib files if you're also including their original source
  • Release and Release-Linux directories
I left the .lib files for ease of convenience and the sources since I thought I should have left them in as per the rules of the forums. As for the rest of the rubbish yes that's my bad I should have cleaned the project folder out a bit better, I will upload a more tidy version when I get the chance.



P.s can I get a mod to change the title (just update the version info to 2.1 pleassssse)
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)