Advertisement
Crenox

Using the Random Class in Java

May 12th, 2015
239
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.32 KB | None | 0 0
  1. EXAMPLE #1
  2. Random rand = new Random();
  3.  
  4. // nextInt is normally exclusive of the top value,
  5. // so add 1 to make it inclusive
  6. int randomNum = rand.nextInt((max - min) + 1) + min;
  7.  
  8. EXAMPLE #2
  9. Math.random() * (Max - Min)
  10.  
  11. LINKS:
  12. http://stackoverflow.com/questions/363681/generating-random-integers-in-a-range-with-java
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement