Perry Smith
Java Questions & Answers
Home /
Java Q & A Archive Page 3 /
Java Q & A Archive
Random Numbers
Sunday, 17-Jan-99 22:42:26
24.128.241.48 writes:
Is there any function to assign a random integer to a variable? I know Math.random()
which only generates double numbers.
Thanks,
Joyce
Responses
Re: Random Numbers
Sunday, 17-Jan-99 23:27:11
142.166.253.83 writes:
I'm not sure whether this is correct
(float)Math.random()
AG
Re: Random Numbers
Monday, 18-Jan-99 00:32:30
24.1.16.214 writes:
there's a public class, java.util.Random, which
has several methods like 'nextInt()' 'nextFloat()'
and so forth.
to flip a coin (random 0 or 1):
Random coin = new Random();
flip_result = Math.abs (coin.nextInt() % 2);
-calyxa
calyxa
Home /
Java Q & A Archive Page 3 /
Java Q & A Archive