Random class acting odd?

后端 未结 6 722
粉色の甜心
粉色の甜心 2020-12-03 21:33

In this code:

Random random = new Random(441287210);
for(int i=0;i<10;i++)
    System.out.print(random.nextInt(10)+\" \");
}

The output

6条回答
  •  醉梦人生
    2020-12-03 21:53

    There's nothing to say that a sequence of 10 1s in a row is not possible. Whoever gave you the seed value 441287210 just happens to have found such a value that results in starting with 10 1s in a row. If you continue calling nextInt() (i.e. more than 10 times) you will see random values. It should be possible to find other seed values that will result in other "apparently non-random" sequences.

提交回复
热议问题