About 50 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 ...

    With Java 8 they introduced the method ints(int randomNumberOrigin, int randomNumberBound) in the Random class. For example if you want to generate five random integers (or a single one) in the …

  3. How Java random generator works? - Stack Overflow

    Feb 17, 2016 · Random r = new Random(); int result = r.nextInt(6); System.out.println(result); I want to know if there is a way to "predict" next generated number and how JVM determines what number to …

  4. 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 do, then, is add …

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

  6. Generate Random numbers without using any external functions

    Feb 23, 2013 · As long as the random numbers aren't very security critical (this would require "real" random numbers), such a recursive random number generator often satisfies the needs. The …

  7. 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 () when

  8. Can Java's random function be zero? - Stack Overflow

    Jun 18, 2010 · Was your CS professor talking about Java, or rather about a purely mathematical random function with equal distribution? Because such a function, for the real numbers range from 0 to 1, …

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

    Did you forget to declare random and assign a new instance of java.util.Random to it?

  10. random function in Java - Stack Overflow

    Mar 24, 2012 · I want to know how to get a 4-digit random number in Java. I was trying to do it and everytime I run the program I always get the same number. Thanks