About 268,000 results
Open links in new tab
  1. Getting random numbers in Java - Stack Overflow

    May 5, 2011 · The first solution is to use the java.util.Random class: import java.util.Random; Random rand = new Random(); // Obtain a number between [0 - 49]. int n = rand.nextInt(50); // …

  2. How do I generate random integers within a specific range in Java ...

    To generate a random number "in between two numbers", use the following code: Random r = new Random(); int lowerBound = 1; int upperBound = 11; int result = r.nextInt(upperBound …

  3. Best way to generate unique Random number in Java

    Sep 13, 2022 · Math.random method : Can Generate Random Numbers of double type. random(), this method returns a double value with a positive sign, greater than or equal to 0.0 and less …

  4. Generating Unique Random Numbers in Java - Stack Overflow

    Jun 18, 2016 · This is the most simple method to generate unique random values in a range or from an array. In this example, I will be using a predefined array but you can adapt this method …

  5. Generating a Random Number between 1 and 10 Java

    import java.util.Random; If you want to test it out try something like this. Random rn = new Random(); for(int i =0; i < 100; i++) { int answer = rn.nextInt(10) + 1; …

  6. How do I generate a random integer between min and max in Java?

    @ataulm: In older versions of Java creating multiple Random objects didn't guarantee randomness. "Two Random objects created within the same millisecond will have the same …

  7. Java random number with given length - Stack Overflow

    Mar 22, 2011 · To generate a 6-digit number: Use Random and nextInt as follows: Random rnd = new Random(); int n = 100000 + rnd.nextInt(900000); Note that n will never be 7 digits …

  8. Get random numbers in a specific range in java - Stack Overflow

    Jul 31, 2012 · Java: generating random number in a range. I want to generate random numbers using . java.util.Random(arg); The only problem is, the method can only take one argument, so …

  9. How to generate 100 random 3 digit numbers in java?

    Aug 30, 2013 · A Set guarantees uniqueness of its values, that's the contract. The HashSet uses the hashCode of the object to ensure that only once instance of each object exists within the …

  10. Generate random integers in java - Stack Overflow

    Jul 22, 2010 · @Tim: True, it eventually has to allocate memory for the whole space - but only if you need to generate every random number in the range. In the case of just 100 choices, pre …

Refresh