java - Does setting a Random objects' seed to a random value make the generator more random? -


i have code simulates 10 coin tosses:

public void flipcointentimes() {     random randomnumbergenerator = new random();      // generate 10 random numbers     (int = 0; < 10; i++) {         randomnumbergenerator.setseed(randomnumbergenerator.nextlong());         system.out.println(randomnumbergenerator.nextint(2) == 0 ? "heads" : "tails");     } } 

does setting of seed random long make method more random? i.e., more 50/50 if remove setseed() line?

no, settings seed not make 'more random'. default constructor use random seed.

the random class uses linear congruential generator generate pseudo random series of bits. state of random class contained in called seed. when class asked random number the seed updated.

it should not affect distribution manually reset distribution of random numbers. if need better distribution harder predict can use securerandom.


Comments

Popular posts from this blog

php - Submit Form Data without Reloading page -

linux - Rails running on virtual machine in Windows -