On Jul 15, 2009, at 11:19 PM, Steve Kroon wrote:

This code should work with "r -= weights[i++]" in the loop body, and comes down to a linear search through

You're right -- I forgot to increment i.

2009/7/16 Peter Drake <dr...@lclark.edu>
     I must be missing something. Isn't the obvious trick:
int r = random(<sum of weights>);
int i = 0;
while (r > weights[i]) {
r -= weights[i];
}
return i;
This way, you only have to generate one random number.

Peter Drake
http://www.lclark.edu/~drake/

_______________________________________________
computer-go mailing list
computer-go@computer-go.org
http://www.computer-go.org/mailman/listinfo/computer-go/

Reply via email to