Posted By

joshnunn on 08/27/09


number random integer generate

Versions (?)

Random Integer between 1 and n

 / Published in: Java


This was an example provided for us to generate a number between 1 and n. The URL included was the best explaination I could find. Substitute any number in place of the 1 for a different starting number. Take the starting number from your highest number, and plug that into n for a different range.

  1. public static int generateRandomNumber(int n){
  2. return (int)(Math.random()*n)+1;
  3. }

Report this snippet  

You need to login to post a comment.