Home » Java Tutorials
 

April
2008

How do I generate a random number between 0 and some integer n

First you would need to create an instance of Random class:
   Random random = new Random();

Then, you can get your random number by calling:
   int pick = random.nextInt(maxvalue);

This would return a value from 0 (inclusive) to maxvalue (excl


1