Re: Random number



Christo <chris.me.white@xxxxxxxxxxx> wrote:
can anyone show me the code to do this very basic code to simply output the
random number that has been generated to the console?

public class RandomCoin {
/** flip a coin. */
public static void main(String[] args) {
java.util.Random rand = new java.util.Random();
System.out.println(rand.nextBoolean() ? "heads" : "tails");
}
}

Of course, if you prefer some other random type than boolean, call the
appropriate method - see the javadoc.

If you're using it for cryptography, you might prefer SecureRandom.
--
Mark Rafn dagon@xxxxxxxxx <http://www.dagon.net/>
.