Java

Java Tutorial 8 – Random Number Generator



pm me with questions or requests

Similar Posts

34 thoughts on “Java Tutorial 8 – Random Number Generator
  1. the parameter that goes inside the nextInt() is exclusive, so sam.nextInt(49) + 1 will generate values in the range [1,50), which is equivalent to [1,49]

  2. Random sam = new Random();
    System.out.println(sam.nextInt(50) + 1);
    This will give you numbers 1 through 50.

    System.out.println(sam.nextInt(49) );
    will give you numbers 0 through 48 which in java is 49 numbers

    System.out.println(sam.nextInt(49) + 1);
    will give you numbers 1 through 49, which in java is 49numbers
    Why didn't we get 50? Because the +1 simply means that the first number will start with 1 instead of 0. the number in quotes is the range from the first number in this case.

    Correct me if I'm wrong please.

  3. Hello!
    Does anybody know how to make a random, non repeated, ordered number generator?
    For ex: We have 1-50, and we want 5 unique random ordered numbers.
    Please, help me as soon as you can!
    Thank You!

  4. Random random = new Random();

    int RandomNumber[];

    while (x <= UserInput){
    RandomNumber[x] = random.nextInt(UserInput) + 1;
    x++;
    }
    i keep getting a null pointer exception though, anyone know why? any help would be appreciated. and yes java.util.Random was imported.
    its been to long since i last programmed 🙁

  5. i want to make a slot machine for mobile phone and i have no ideea how to start , i uses visual studio 2010 for 2 years , can u make a tutorial ?

    how to declare variabiles, how to change pictures , how to resize pictures, how to work with variabiles …. goshhhh is so hard to understand netbeans …

Leave a Reply

Your email address will not be published. Required fields are marked *