Solved Random number

Discussion in 'Plugin Development' started by NickDEV, Sep 15, 2015.

Thread Status:
Not open for further replies.
  1. Offline

    NickDEV

    How to generate a random number from 0 to 15? (I would like to use that random generated number as int number)
     
  2. Offline

    BrickBoy55

    @NickDEV
    Create a random with 15 as the constructor, then do:
    Code:
    int number = <your random>.nextInt() + 1;
    
     
  3. Offline

    NickDEV

  4. Offline

    BrickBoy55

    @NickDEV What you would name your random variable.
     
  5. Offline

    NickDEV

    @BrickBoy55 I don't know how to get a random number...
     
  6. Offline

    Hawktasard

    @NickDEV
    You can do something like this:
    Code:java
    1. double myNumber = Math.random() * 15;

    edit: You should probably use Random though:
    Code:java
    1. Random random = new Random();
    2. int num = random.nextInt(150);
     
  7. Offline

    BrickBoy55

    @NickDEV You'd do something like this:
    Code:
    Random random = new Random(15); //Creating a new random variable with the name random, that holds can go up to 14.
    int number = random.nextInt() + 1; // Making the random generate a random number. Adding 1 will make it so it is possible to get 15 as a number.
     
    NickDEV likes this.
  8. Offline

    NickDEV

  9. Offline

    BrickBoy55

Thread Status:
Not open for further replies.

Share This Page