I tried creating a random number generator
java.util.Random rand = new java.util.Random()
and then asking it for a random int
rand.nextInt()
which I would then take modulo the board size to choose a random
point. Since ints in Java are signed, I would have to take the
absolute value of this int before the modulo operaton. (As in C/C++,
Java's % operator does not behave as modulo, in the mathematical
sense, when the first argument is negative. It might more accurately
be called "remainder".)
This almost always works, but once in a very great while I would get
a negative result anyway. I eventually hunted down the problem, which
is explained in the API for the java.lang.Math.abs() method:
"Note that if the argument is equal to the value of
Integer.MIN_VALUE, the most negative representable int value, the
result is that same value, which is negative."
Yikes!
So, I'll have to check the sign of my result and try again in those
rare (but not ignorably rare) instances where it is negative.
I hope this saves some time for the next person to encounter this
problem.
Peter Drake
Assistant Professor of Computer Science
Lewis & Clark College
http://www.lclark.edu/~drake/
_______________________________________________
computer-go mailing list
[email protected]
http://www.computer-go.org/mailman/listinfo/computer-go/