Skip to main content
GameDev.net gamedev.net
🔒 Locked

random() ?

Started by browny Feb 20, 2003 at 5:19 AM 7 replies 250+ views
Original Post
browny
browny
How do you generate a random number without using any lib-functions like "rand()" or like such. An algorithm or source-code would be highly appreciated.
Z
Shag
Shag
try here

http://www.math.keio.ac.jp/~matumoto/emt.html

and look for the ''c codes'' section.

I don''t understand why everyone doesn''t use this generator - it produces a range of 2^32-1 random numbers, over a much longer period than the built in rand() ... and if that isn''t good enough ... it''s actually faster too

Regards
Metal Typhoon
Metal Typhoon
quote:
Original post by Shag
try here

http://www.math.keio.ac.jp/~matumoto/emt.html

and look for the ''c codes'' section.

I don''t understand why everyone doesn''t use this generator - it produces a range of 2^32-1 random numbers, over a much longer period than the built in rand() ... and if that isn''t good enough ... it''s actually faster too

Regards


am i wrong or using a srand will create larger than that ?
srand ((unsigned) time (NULL)) ?
Metal Typhoon
Shag
Shag
No - the rand function only returns a number between 0-2^15

Look for the MAX_RAND (i think) definition


[edited by - Shag on February 20, 2003 7:50:29 AM]
browny
browny
is that a Japanese site you gave me ? My browser doesn''t support japanese and it wouldn''t make much difference even if it did. So, why dont you simply tell me the basic theory behind it
Z
Shag
Shag
Believe me, my japanese isn''t as good as it could be - the site is in english!

However, there is a dialog that pops up about installing some foreign font - i just ignore it and everything is fine
Shag
Shag
OOPS

I never actually told you what the site was about!

There is a random number generator called a Mersenne Twister. This is what i was pointing you too!

Do a search in google
jperalta
jperalta
Here''s one you might try:


unsigned long Rand(unsigned long* seedP) {
unsigned long seed = *seedP;
unsigned long rval = 0;
__asm {
mov eax,343FDh;
imul seed;
add eax,269EC3h;
mov seed,eax;
ror eax,8;
mov rval,eax;
}
*seedP = seed;
return rval;
}


-- Exitus Acta Probat --

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.