How to include negative numbers in random number generation?
Hello,I have been trying to create 100 random integers that has just -1, 0 and 1. But since this range has a negative number, I'm confused as what method to use. Any help would be greatly appreciated.Thanks.
[229 byte] By [
Raj06a] at [2007-11-26 21:27:33]

Using java.util.Random can you just generate 0, 1 and 2? Then what can youdo to 0, 1 and 2 to transform them to -1, 0 and 1?
public class Randoms {
public static void main(String[] args) {
Random rand = new Random(System.currentTimeMillis());
for(int i = 0; i < 100; i++) {
int r = rand.nextInt(2) -1;
System.err.println(r);
}
}
}