0

For some reason I am receiving this error , cannot find symbol, method Math random() not found . If anyone knows why it would be of great help.

int digit1 = (int)(Math.random() * 10);
int digit2 =(int)(Math.random()* 10);

this is supposed to give me two separate random digit variables between 1 and 10 I thought. Whats wrong with my code please help.

1
Contributor
4
Replies
7
Views
4 Years
Discussion Span
Last Post by cobalt555
0

Ok so I need to take the above code and have it only randomly generate numbers between 1-9 . I cannot have zero and I cannot have 10 in it.int digit1=(int) (Math.random()*9) what would I need to do to get rid of zero here and make it 1-9. I think that will make it 0-9 correct?

0

int digit1 =(int) (Math.random()*10-1); This is my idea can anyone confirm if this will produce random numbers between 1-9?

This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.