0
Java Math.random to get a random double digit between two number
If i want a random digit between 5.0 and 10.0 using Java Math.random, am i suppose to use Math.random()*5 +5? Note that i want to include 10.0 as well
2 Answers
+ 1
Math.random() *(10.0-5.0+1 ) + 5.0 ;
( this generates greater than 5.0 and less than 11.0) , if you don't want above 10.0 then don't add +1.
it's Same farmulae as the previous one:
(int) (Math.random() *(Max-Min+1) +Min)
If you want integer type (without fraction part) cast to int.
0
You were close.
https://code.sololearn.com/cP2XToLXHEXF/?ref=app