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

    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:

  3. How do you use math.random to generate random ints?

    Dec 23, 2011 · Please remove the import statement importing java.util package. then your program will use random() method for java.lang by default and then your program will work. …

  4. java - Math.random () explanation - Stack Overflow

    Nov 1, 2011 · This is a pretty simple Java (though probably applicable to all programming) question: Math.random() returns a number between zero and one. If I want to return an integer …

  5. 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 …

  6. 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?

  7. Random numbers with Math.random() in Java - Stack Overflow

    Oct 27, 2011 · 2 If min = 5, and max = 10, and Math.random() returns (almost) 1.0, the generated number will be (almost) 15, which is clearly more than the chosen max. Relatedly, this is why …

  8. 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 …

  9. java - Random over ThreadLocalRandom - Stack Overflow

    Dec 3, 2020 · Quoted from source: Normally to generate random numbers, we either do create an instance of java.util.Random or Math.random() - which internally creates an instance of …

  10. Java random numbers using a seed - Stack Overflow

    Sep 17, 2012 · This is my code to generate random numbers using a seed as an argument: double randomGenerator(long seed) { Random generator = new Random(seed); double num …