#1
  1. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    May 2013
    Posts
    1
    Rep Power
    0

    Creating a Secret Numbers game, need help with random.


    So I am trying to come up with a game that has three levels, easy, medium, and hard as well as a custom. The problem I have is creating a random integer that allows there to be a minimum of 1 and a max of 10 for easy, min of 1 and a max of 25 for medium, and a min of 1 and a max of 100 for hard. The custom difficulty just has a minimum but no max.

    This is my method:

    public static int randInt(int max)
    {
    int min = 1;

    java.util.Random rand = new java.util.Random();
    return rand.nextInt(max - min) + min;
    }

    Any help would be great.
  2. #2
  3. Contributing User
    Devshed Expert (3500 - 3999 posts)

    Join Date
    Aug 2010
    Location
    Eastern Florida
    Posts
    3,711
    Rep Power
    347
    Use if/else if statements to test for what max to use.

IMN logo majestic logo threadwatch logo seochat tools logo