On Thu, 2006-12-07 at 16:05 +0100, Ćukasz Lew wrote:
> ii = pm::rand () % empty_v_cnt; // TODO improve speed "%"
Try this, I think it could be faster, not sure, but has the advantage
that it's slightly more correct.
// returns an integer between 0 and n-1 inclusive
//
unsigned long randint(unsigned long n)
{
unsigned long v = n;
unsigned long r;
v--;
v |= v >> 1;
v |= v >> 2;
v |= v >> 4;
v |= v >> 8;
v |= v >> 16;
do { r = rand(); } while ( (r & v) >= n );
return( r & v );
}
- Don
_______________________________________________
computer-go mailing list
[email protected]
http://www.computer-go.org/mailman/listinfo/computer-go/