Author: Dieter Buerssner
Date: 05:28:10 11/04/02
Go up one level in this thread
On November 04, 2002 at 04:59:03, Uri Blass wrote: >If I use rand instead of rand64 I get 38 in both cases >Here is my function rand64 that is in another file in my project. > >__int64 rand64() >{ > return rand()^((__int64)rand()<<15)^((__int64)rand()<<30)^ > ((__int64)rand()<<45)^((__int64)rand()<<60); >} Without checking the C-Standard, this looks wrong to me. I think, it is not guaranteed, in which order rand() is called for producing the parts of the expression: __int64 rand64() { __int64 r; r = rand(); r ^= rand() << 15; ...; return r; } I would use unsigned __int64. A portable an rather decent PRNG based on Maraglia: static unsigned long zseed = 0x12345678UL; static unsigned long wseed = 0x87654321UL; static unsigned long mwc1616(void) { unsigned long t = zseed; zseed=30903*(t&0xffff)+(t>>16); t = wseed; wseed=18000*(t&0xffff)+(t>>16); return ((wseed<<16)&0xffffffffUL) + (zseed&0xffff); } static void seed_mwc1616(unsigned long s) { zseed = s&0xffffffffUL; wseed = (s*1103515245UL + 12345)&0xffffffffUL; } mwc1616 (combine 2 16 bit multiply with carry generators) returns 32 bit random numbers. Regards, Dieter
This page took 0 seconds to execute
Last modified: Thu, 15 Apr 21 08:11:13 -0700
Current Computer Chess Club Forums at Talkchess. This site by Sean Mintz.