Original Post
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.
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
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;
}
This topic has been locked by a moderator. New replies are not allowed.
With your permission, GameDev.net uses analytics cookies to understand how people use the platform. You can accept analytics or continue with necessary cookies only. Learn more