CHowdappaM - 1 year ago 67

Java Question

If I set seed in Random why always get same random number in below code:

`private static void createArray(int[] x) {`

for(int i =0; i<x.length; i++){

Random random = new Random(500l);

x[i] = random.nextInt(100000); //53695

}

}

I am getting 53695 for every run and entire loop.

Recommended for you: Get network issues from **WhatsUp Gold**. **Not end users.**

Answer Source

Because that's what happens when you use the same seed in a pseudo-randomnumber generator. It's not random, it just looks "random enough", but it's all thanks to a deterministic mathematical formula.

Use `SecureRandom`

if you need better randomness.

Here are some examples of seeds that provide "interesting" "random" numbers: http://insights.dice.com/2014/01/24/generating-random-numbers-javas-random-class/

Recommended from our users: **Dynamic Network Monitoring from WhatsUp Gold from IPSwitch**. ** Free Download**