method for randomly selecting boolean value

L

Lew

Ashoka! said:
Generate a random integer by using the random class <http://
java.sun.com/j2se/1.5.0/docs/api/java/util/Random.html> and then use
int bValue = randomInt % 2;
to get a o or 1 value.

Didn't the OP ask for boolean results?

-- Lew
 
P

Patricia Shanahan

Ashoka! said:
Generate a random integer by using the random class <http://
java.sun.com/j2se/1.5.0/docs/api/java/util/Random.html> and then use
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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,755
Messages
2,569,534
Members
45,008
Latest member
Rahul737

Latest Threads

Top