+ 1

how to random numbers in java

17th Apr 2017, 6:08 AM
Satyaki Ray
2 Answers
+ 7
System.out.print( new java.util.Random().nextInt(100)//Random at here ); Or the simplest way System.out.print( Math.round(Math.random()*100) )
17th Apr 2017, 6:22 AM
Yanothai Chaitawat
Yanothai Chaitawat - avatar
+ 3
double x = Math.random(); Returns a double value with a positive sign, greather than or equal to 0.0 and less than 1.0. To obtain the required range use type casting and mathematical operations, ex: (int)((Math.random()+1)*10); Returns an integer value in the range between 10 and 19.
17th Apr 2017, 6:36 AM
Alexey
Alexey - avatar