enow.com Web Search

Search results

  1. Results from the WOW.Com Content Network
  2. Getting random numbers in Java - Stack Overflow

    stackoverflow.com/questions/5887709

    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); // Add 1 to the result to get a number from the required range // (i.e., [1 - 50]). n += 1; Another solution is using Math.random(): double random = Math.random() * 49 + 1 ...

  3. The Java Math library function Math.random() generates a double value in the range [0,1). Notice this range does not include the 1. In order to get a specific range of values first, you need to multiply by the magnitude of the range of values you want covered. Math.random() * ( Max - Min )

  4. Java Generate Random Number Between Two Given Values

    stackoverflow.com/questions/5271598

    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 ONE CERTAIN NUMBER to the number generated, which will cause the number to be within a range.

  5. how does random () actually work? - Stack Overflow

    stackoverflow.com/questions/1359318

    random() is a so called pseudorandom number generator (PRNG). random() is mostly implemented as a Linear congruential generator. This is a function of the form X(n+1) (aXn +c) modulo m. Xn is the sequence of generated pseudorandom numbers. The genarated sequence of numbers is easy guessable.

  6. @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 sequence of random numbers." . In newer versions it is probably OK, but I didn't know that when I wrote my comment three years ago. –

  7. random function in Java - Stack Overflow

    stackoverflow.com/questions/9847169

    But please now I need to do same random but with a 16-digit number. And the random function I got doesn't work with big numbers. I got this function: int pin = new Random().nextInt(10000); But if I put a big number like 1000000000000, it won't work because it's not int, and the nextLong is not working to me like that. –

  8. Java random numbers using a seed - Stack Overflow

    stackoverflow.com/questions/12458383

    The sequence is not truly random in that it is completely determined by a relatively small set of initial values, called the PRNG's state, which includes a truly random seed. If you want to have different sequences (the usual case when not tuning or debugging the algorithm), you should call the zero argument constructor which uses the nanoTime ...

  9. There are many ways to do this, but yes, it involves generating a random int (using e.g. java.util.Random.nextInt) and then using that to map to a char. If you have a specific alphabet, then something like this is nifty: import java.util.Random; //...

  10. Now, if you do need it to be random, we first note a generated sequence of numbers that contain no duplicates can not be called random. :p Now that we get that out of the way, the fastest way to do this is to have a Hashtable or HashMap containing all the IDs already generated. Whenever a new ID is generated, check it against the hashtable, re ...

  11. Using random with strings in java ? - Stack Overflow

    stackoverflow.com/questions/10918350

    Then get a random integer from the Random class that's within the bounds of the length of your array (look at the modulo % operator to figure out how to do this; alternatively, constrain the call to random.nextInt() by passing an uppper bound). Get the string by indexing into the array with the number you just got.