0

I came across a code snippet on internet. Here it goes

  public class Test {

    public static void main(String[] args) {
    Random random = new Random(441287210);  

    for(int j=0;j<10;j++) { 

           System.out.print(random.nextInt(10)+" ");  

    } 
}

}

Everytime i run it it prints 1 1 1 1 1 1 1 1 1 1 . There might be a strong reason for it.

Why is this behaviour observed.

Here is the source --> http://www.javacodegeeks.com/2011/10/weird-funny-java.html

6
  • 1
    Why does it surprise you that there is a particular seed that would generate this exact sequence of random integers? Commented Jul 16, 2014 at 13:49
  • The "every time" part is because it's using the same seed. That particular seed probably has the 1 in 10,000,000,000 chance that it returns 1 for the first ten times. Commented Jul 16, 2014 at 13:50
  • 3
    This is a bit like successfully guessing last week's lottery numbers. Commented Jul 16, 2014 at 13:51
  • 3
    Sorry, couldn't resist. Commented Jul 16, 2014 at 13:52
  • 2
    @BoristheSpider couldn't resist either Commented Jul 16, 2014 at 14:07

2 Answers 2

8

You're initializing the pseudorandom number generator to a specific state, which means that it will always produce the same output across runs. It looks like someone just found a seed that happens to produce an interesting series of results.

Sign up to request clarification or add additional context in comments.

Comments

1

Every Random seed generates identical sequences of numbers. 441287210 seed generates this sequence, just as any other generated sequence...

From documentation:

If two instances of Random are created with the same seed, and the same sequence of method calls is made for each, they will generate and return identical sequences of numbers

1 Comment

I thought I've used quotes... Thanx!

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.