c# - Why initialize a new Random() with unchecked(Environment.TickCount * 31)? -


i found initialization of random instance:

var random = new random(unchecked(environment.tickcount * 31)); 

why not use new random()?

the keyword unchecked prevents exception being thrown when calculation environment.tickcount * 31 integer overflows.

the resulting calculation random integer (it throws away bunch of high-order bits), used seed random number generator.

note reference source random has code parameterless constructor:

public random()      : this(environment.tickcount) {   } 

Comments