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.

29th Aug 2017, 2:46 PM
ALEX
ALEX - avatar
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
29th Aug 2017, 2:59 PM
Shamima Yasmin
Shamima Yasmin - avatar
+ 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);
29th Aug 2017, 5:11 PM
ChaoticDawg
ChaoticDawg - avatar
+ 4
It returns a random double from (inclusive) 0 to 1 (exclusive)
29th Aug 2017, 5:00 PM
Rrestoring faith
Rrestoring faith - avatar