> On Mar 10, 3:58 am, "Daniel Pitts" <googlegrou...@coloraura.com>
> wrote:
[quoted text clipped - 7 lines]
> int bValue = randomInt % 2;
> to get a o or 1 value.
Didn't the OP ask for boolean results?
-- Lew
> On Mar 10, 3:58 am, "Daniel Pitts" <googlegrou...@coloraura.com>
> wrote:
[quoted text clipped - 7 lines]
> int bValue = randomInt % 2;
> to get a o or 1 value.
If {0,1} is really wanted, why not use myRandom.nextInt(2)? Or if a
boolean is wanted, myRandom.nextBoolean()?
The first step, of course, is for the OP to decide whether the values
should be boolean or {0,1}.
Patricia
Alex Hunsley - 10 Mar 2007 21:48 GMT
>> On Mar 10, 3:58 am, "Daniel Pitts" <googlegrou...@coloraura.com>
>> wrote:
[quoted text clipped - 10 lines]
> If {0,1} is really wanted, why not use myRandom.nextInt(2)? Or if a
> boolean is wanted, myRandom.nextBoolean()?
In fact, nextInt(2) is much preferred to the modulus way of doing things
(i.e. randomInt % 2), since the mod method tends to give less random
results.
And if crypto grade (pseudo) randomness is required, used SecureRandom
or similar.
http://java.sun.com/j2se/1.4.2/docs/api/java/security/SecureRandom.html
> The first step, of course, is for the OP to decide whether the values
> should be boolean or {0,1}.
>
> Patricia