Re: [computer-go] Unsigned random numbers in Java

2006-12-21 Thread John Tromp

On 21 Dec 2006 21:41:25 +, David Denholm [EMAIL PROTECTED]
wrote:


John Tromp [EMAIL PROTECTED] writes:

 Or use (r  (-11)) to obtain a nonnegative value (instead of abs(r)),

I think you meant  (-1  1)  : (-1  1)  is still -1  since  is
a signed shift (preserves top bit).  is the unsigned shift which
clears top bit.



Right you are:)

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

Re: [computer-go] Unsigned random numbers in Java

2006-12-20 Thread Ephrim Khong
Peter Drake wrote:
 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.

Note that rand.nextInt(int n) might be what you want: Returns a
pseudorandom, uniformly distributed int value between 0 (inclusive) and
the specified value (exclusive), drawn from this random number
generator's sequence.. This also takes into account that simply taking
the modulus does usually _not_ result in a uniformly distribution, since
usually MAX_INT is no multiple of n.

greets
eph

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