SA-MP Forums Archive
[Include] Random - Printable Version

+- SA-MP Forums Archive (https://sampforum.blast.hk)
+-- Forum: SA-MP Scripting and Plugins (https://sampforum.blast.hk/forumdisplay.php?fid=8)
+--- Forum: Filterscripts (https://sampforum.blast.hk/forumdisplay.php?fid=17)
+---- Forum: Includes (https://sampforum.blast.hk/forumdisplay.php?fid=83)
+---- Thread: [Include] Random (/showthread.php?tid=256867)



Random - sciman001 - 22.05.2011

Hi all. I was just.. playing around with some code and made this random function. Heres the link:

SolidFiles

Example:

pawn Код:
printf("%d", rand());
This thing is COMPLETELY random! And it ONLY generates POSITIVE numbers! Thanks for ur time. PLEASE LEAVE A COMMENT!!!

NOTE:
This function takes like.. A TON of cpu, recources, memory, etc. Be careful when using it. DONT CALL IT MORE THAN TEN TIMES IN A ROW... THX!



Re: Random - Macluawn - 22.05.2011

Whats wrong with using random(max) ?


Re: Random - sciman001 - 22.05.2011

its not COMPLETELY random. Plus, mines cooler.


Respuesta: Random - admantis - 22.05.2011

pawn Код:
random(7000000);
Tadб!!!


Re: Random - Macluawn - 22.05.2011

It can be predicted knowing that code, since it's using gettime.


Re: Random - sciman001 - 22.05.2011

but... not completely... right?... it has a bunch of random() fundtions in it to make it more random.. so.. it should be almost unpredictable... right?


Respuesta: Random - admantis - 22.05.2011

Quote:
Originally Posted by admantis
Посмотреть сообщение
pawn Код:
random(7000000);
Tadб!!!
Once again, tadб!!!!


Re: Random - marinov - 22.05.2011

Quote:
Originally Posted by sciman001
Посмотреть сообщение
NOTE:
This function takes like.. A TON of cpu, recources, memory, etc. Be careful when using it. DONT CALL IT MORE THAN TEN TIMES IN A ROW... THX!
Trash


Re: Random - RyDeR` - 22.05.2011

pawn Код:
#define rand() \
    random(cellmax)
Tada! You can't have higher then cellmax as integer in PAWN, so this will be the most efficient way to do this.


Re: Random :/ - sciman001 - 22.05.2011

Ok guys, this was just a little experiment to see how it worked out. It does do the job... but, its a bit.. INEFFICENT. :d Anyway, sorry to bother, but.. idk. I just wanted to see what you guys would think of it. :/


Re: Random - playbox12 - 22.05.2011

Don't really see the use of it, next time use pastebin though, for such scripts.
(Btw, your location doesen't really make sense;

C:/a/b/me.amx

How I look at it that would mean

'a' is in drive C, 'b' is an part of 'a' so that makes 'me' a part of 'a's b'. So you just described your location inside an 'b'?)


Re: Random - Y_Less - 23.05.2011

Why have you used the numbers and algorithms you have in that code? Do you have any references to justify those choices and prove that this is COMPLETELY random - because I'm sorry to tell you that it's not!

"random" is a pseudo-random number generator. That means it has a predictable, though highly complex and long, pattern to the numbers it generates. Your code, being based on "random" and basic maths, will also have a predictable pattern. This is no better or worse than "random", it may just give a different distribution of numbers to "random" which appears better for your uses.

There are large numbers of research papers on better pseudo-random number generation techniques. One famous one (for which there is already a SA:MP plugin) is the Mersenne Twister.

Links (note that some of these are behind paywalls, if you are at a university or similar institution/company you may still be able to see them):

http://portal.acm.org/citation.cfm?id=272995 - Mersenne Twister.
http://epubs.siam.org/sicomp/resourc...v15/i2/p364_s1 - 1/P generator.
http://scholar.******.co.uk/scholar?...-random+number - Many more links.

If you want to write a good random number generator and claim that it is good, you need to be able to show that it is good - and that is non-trivial! Hence why people can write advanced maths research papers for publication.