[computer-go] Fast random int generation
Łukasz Lew
lukasz.lew at gmail.com
Thu Aug 31 05:56:39 PDT 2006
Someone (Don?) asked for a fast random generator.
Here it is.
Standard library rand() in linux takes about 200 clock cycles.
pm::rand() takes 30cc on my hardware.
namespace pm {
static unsigned long seed = 12345;
unsigned long rand () {
unsigned long hi, lo;
lo = 16807 * (seed & 0xffff);
hi = 16807 * (seed >> 16);
lo += (hi & 0x7fff) << 16;
lo += hi >> 15;
if (lo > 0x7fffffff) lo -= 0x7fffffff;
seed = (long) lo;
return lo;
}
}
Regards,
Łukasz
More information about the computer-go
mailing list