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

    May 5, 2011 · I would like to get a random value between 1 to 50 in Java. How may I do that with the help of Math.random();? How do I bound the values that Math.random() returns?

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

    Java 7+ In Java 1.7 or later, the standard way to do this (generate a basic non-cryptographically secure random integer in the range [min, max]) is as follows: import …

  3. Generating Unique Random Numbers in Java - Stack Overflow

    Jun 18, 2016 · With Java 8+ you can use the ints method of Random to get an IntStream of random values then distinct and limit to reduce the stream to a number of unique random …

  4. Generating a Random Number between 1 and 10 Java

    I want to generate a number between 1 and 10 in Java. Here is what I tried: Random rn = new Random(); int answer = rn.nextInt(10) + 1; Is there a way to tell what to put in the parenthesis …

  5. How to randomly pick an element from an array - Stack Overflow

    Apr 23, 2015 · I am looking for solution to pick number randomly from an integer array. For example I have an array new int[]{1,2,3}, how can I pick a number randomly?

  6. java - Picking a random element from a set - Stack Overflow

    Dec 26, 2023 · How do I pick a random element from a set? I'm particularly interested in picking a random element from a HashSet or a LinkedHashSet, in Java.

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

    What method returns a random int between a min and max? Or does no such method exist? What I'm looking for is something like this: NAMEOFMETHOD (min, max) (where min and max are …

  8. java - Generate a random double in a range - Stack Overflow

    EDIT: new Random().nextDouble(): randomly generates a number between 0 and 1. start: start number, to shift number "to the right" end - start: interval. Random gives you from 0% to 100% …

  9. Java Generate Random Number Between Two Given Values

    Mar 11, 2011 · Java doesn't have a Random generator between two values in the same way that Python does. It actually only takes one value in to generate the Random. What you need to …

  10. Java random number with given length - Stack Overflow

    Mar 22, 2011 · I need to genarate a random number with exactly 6 digits in Java. I know i could loop 6 times over a randomizer but is there a nother way to do this in the standard Java SE?

Refresh