math.Random isn't working right
- by RandomlyKnighted
I'm trying to simulate a coin flip using the code below.
public class Coin
{
public static double result;
int[] count = new count[2];
public static void flip()
{
result = Math.random();
}
public static boolean isHeads()
{
if (result == 0.0)
{
count[0]++;
return false;
}
else
{
count[1]++;
return true;
}
}
public static void main(String[] args)
{
flip();
isHeads();
System.out.println(count[0]);
System.out.println(count[1]);
}
}
For some reason Eclipse says that the
import java.util.Random;
is never used even though I'm clearly using it. I didn't put my for loop into the code above but it loops n number of times and then outputs the result. No matter how many times it loops it always returns that the result is greater than 0.0 which can't be right. Am I calling Math.random incorrectly?