About 60,800 results
Open links in new tab
  1. java - Math.random() explanation - Stack Overflow

    Nov 1, 2011 · Math.random() returns a number between zero and one. If I want to return an integer between zero and hundred, I would do: (int) Math.floor(Math.random() * 101) Between …

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

    Oct 27, 2011 · (int)(Math.random() * max) + min gives a result between 10 and 110, while (int)(Math.random() * (max - min) + min) gives a result between 10 and 100, so they are very …

  3. 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); // …

  4. java - How do you use math.random to generate random ints

    Dec 22, 2011 · For your code to compile you need to cast the result to an int. int abc = (int) (Math.random() * 100); However, if you instead use the java.util.Random class it has built in …

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

    The Math.Random class in Java is 0-based. So, if you write something like this: Random rand = new Random(); int x = rand.nextInt(10); x will be between 0-9 inclusive. So, given the following …

  6. java - Math.random () v/s Random class - Stack Overflow

    The Math class in Java has a method, Math.random() which returns a pseudorandom number between 0 and 1. There is also a class java.util.Random which has various methods like …

  7. How does Math.random () EXACTLY work in Java? - Stack Overflow

    Dec 15, 2017 · This is where math.random( ) comes in. This line of code: int random_num = (int) (Math.random() * 6) + 1; CAN generate random numbers between 1 to 6. My problem lies at …

  8. Java random number with given length - Stack Overflow

    To generate a 6-digit number: Use Random and nextInt as follows:. Random rnd = new Random(); int n = 100000 + rnd.nextInt(900000);

  9. java - Random number with Probabilities - Stack Overflow

    Dec 2, 2013 · I am wondering what would be the best way (e.g. in Java) to generate random numbers within a particular range where each number has a certain probability to occur or …

  10. java - Assigning math.random value to array - Stack Overflow

    Jun 20, 2012 · I have a quick question I am testing out the Math.random functionality. I am trying to assign the result from the (int) (Math.random()*6)+1 for each one of the 100 boxes to an …

Refresh