+ 1
I need help with something!
How can I create a random number in java?
2 Answers
+ 1
/*Random numbers until 50*/
import java.util.Random;
Random rand = new Random();
int n = rand.nextInt(50) + 1;
+ 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.