[Include] Random
#1

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!
Reply
#2

Whats wrong with using random(max) ?
Reply
#3

its not COMPLETELY random. Plus, mines cooler.
Reply
#4

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

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

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?
Reply
#7

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

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
Reply
#9

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.
Reply
#10

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. :/
Reply
#11

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'?)
Reply
#12

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.
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)