Math.random()
returns double
value in range [0, 1) (greater than or equal to 0.0 and less than 1.0). Then you cast that double
value to int
, so it always results in 0. After that you add 1 to it, so the result always remains 1.
You should cast result of multiplication - Math.random() * 6
instead of casting Math.random()
return value:
rolls1[i] = (int)(Math.random()*6)+1;
By the way, you should be aware of operators precedence in Java language. You can have a look here: operator precedence to see nice table that shows that casting has a higher priority than multiplication and addition - this is the reason, why (Math.random()*6)
is put in parenthesis for casting (this way you avoid casting only Math.random()
)
PS. There is also a link to table of operator precedence in official Java tutorial, but it doesn't exactly fit to your problem as it doesn't contain operation of casting - this is the reason, why I provided another link firstly.