java - What is seed in util.Random? -
i can't understand meaning of seed in java.util.random ? had read why code print “hello world”? question , still confuse seed . can describe me kindfully seed mean ? thanks.
in documentation setseed() method ... mean seed - initial seed
?
public void setseed(long seed)
sets seed of random number generator using single long seed. general contract of setseed alters state of random number generator object in same state if had been created argument seed seed. method setseed implemented class random atomically updating seed to
(seed ^ 0x5deece66dl) & ((1l << 48) - 1)
, clearing havenextnextgaussian flag used nextgaussian().
implementation of setseed class random happens use 48 bits of given seed. in general, however, overriding method may use 64 bits of long argument seed value. parameters:
seed - initial seed
i expect if can understand meaning of seed
, sure understand this answer.
a pseudo-random number generator produces sequence of numbers. isn't random, mathematical calculation produces output matches desirable distribution, , without obvious patterns. in order produce such sequence, there must state stored generator able generate next number in sequence. state updated each time using part of output previous step.
seeding explicitly initialises state. 'seed' starting point, grows. in case, sequence of numbers.
this can used either generate same sequence (by using known constant seed), useful having deterministic behaviour. debugging, network applications, cryptography, etc.
or, in situations want behaviour unpredictable (always different each time run program, card game perhaps), can seed number continually changing, such time.
the 'randomness' of sequence not depend on seed chosen, though depend on not reseeding sequence.
this should answer question.
Comments
Post a Comment