0
How to use Math.random in java?
how to use Math.random in the math class ? Can u show it by using it in a program . Thanks for noticing me.
4 Antworten
+ 6
Here you go, you can generate any random number within min and max range as follows :
I've used here 100 and 200 as min and max value, respectively.
https://code.sololearn.com/c21TGTpX7pL9/?ref=app
+ 5
FYI in addition to Math.random() there is also:
import java.util.Random
int max = 200;
int min = 100;
int n = new Random().nextInt(max - min) + min + 1;
and
import java.util.concurrent.ThreadLocalRandom;
int max = 200;
int min = 100;
int n = ThreadLocalRandom.current().nextInt(min, max + 1);
+ 4
It returns a random double from (inclusive) 0 to 1 (exclusive)