Random Int

Discussion in 'Programming' started by FloThePony, May 11, 2015.

  1. Here is my code:
    Code (Text):
    public static int = Random;

    if(Random() == 1) {
    // Do this
    }
    if(Random() == 2) {
    // Do that
    }
    if(Random() == 3) {
    // Do this
    }
     
    How would I set the int to a random number between like 1 and 20 or something?
    Thanks
    - Flo
     
    • Agree Agree x 1
    • Friendly Friendly x 1
  2. Code (Text):
    Random random = new Random();
    int randomInt = random.nextInt(19);
    randomInt++;
    ^ Because nextInt(); starts with 0
     
  3. I hate you a bit right now. Literally 5 seconds.
     
    • Funny Funny x 2
  4. Thanks