+ 1
how to random numbers in java
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)
)
+ 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.