+ 1

I need help with something!

How can I create a random number in java?

24th Jul 2018, 11:49 AM
Giorgos
Giorgos - avatar
2 Answers
+ 1
/*Random numbers until 50*/ import java.util.Random; Random rand = new Random(); int n = rand.nextInt(50) + 1;
24th Jul 2018, 11:59 AM
Yuri Biasi
Yuri Biasi - avatar
+ 2
just to clarify after you make your random object this code int n = rand.nextInt(50)+1; will generate a random number between 1 and 50 this is called inclusive because it includes 1 and 50 this code int n = rand.nextInt(50): is called exclusive because it will generate random numbers between 0 and 49 excluding 50.
24th Jul 2018, 12:33 PM
StealthyTaco
StealthyTaco - avatar