Talk About Network



Register and Login
Nick
Password
Register create new account Sign up is FREE and you can post replies, new topics, bookmark posts and more!
Recover lost password


Programming > Apl > Re: picking a n...
Latest [ Topics | Posts ] Archive Post A New Topic Post a Reply
<< Topic < Post Post 12 of 12 Topic 941 of 1019
Post > Topic >>

Re: picking a new random seed

by Charles Brenner <cbrenner@[EMAIL PROTECTED] > Feb 3, 2008 at 01:59 PM

On Jan 30, 1:57 pm, "James J. Weinkam" <j...@[EMAIL PROTECTED]
> wrote:
> Charles Brenner wrote:
> > On Jan 27, 1:33 pm, "Curtis A. Jones" <curtis_jo...@[EMAIL PROTECTED]
> wrote:
> >> Charles,
> >> Simply constructing an integer from the system clock to use as the
> >> seed {quadRL} for the random number generator may give a less than
> >> ideal sequence.
>
> >> James J. Weinkam discusses this in this comp.lang.apl group under
> >> "Random Number Generation in IP Sharp APL" (29 Jun 2006
1917)http://groups.google.com/group/comp.lang.apl/browse_frm/thread/33c60d...
>
> >> Among the consequences of a poor choice of seed:
> >> "Moreover choosing a seed which is nor relatively prime to the
modulus
> >> causes the generator to produce a subsequence which is not of maximum
> >> length."
>
> >> One recommendation he makes:
> >> "...saving the value of the seed at the end or each run and using
that
> >> value to seed the generator at the start of the next run."
>
> > Yes, I thought of that but would rather not decide on all the
> > housekeeping issues.
>
> >> I imagine you know this and have a function that selects only "valid
> >> values for {quadRL}" from the clock.  Would you share it?
>
> > That's quite easy. The random number generation algorithm is
> > multiply by 5*7
> > reduce modulo (2*31)-1.
> > This algorithm generates every possible value before it repeats (I
> > checked the cycle length, which didn't take very long. In formal
> > language, the modulus is a prime and 5*7 is a primitive root, meaning
> > a number whose powers include every modulus class except 0. The fact
> > is that every prime does have primitive roots, so once you realize
> > that (2*31)-1 is a prime it follows that unless the implementor
> > blundered remarkably, the chosen multiplier must be a primitive root
> > and the generated numbers must be the full cycle. There was really no
> > need to check.)
>
> > That is, all numbers
> > 0 < n < 2*31
> > are in the cycle, so start with any one of them. For example
>
> > 1. Hash the system clock or whatever to a number. To ensure a valid
> > and efficient []RL
> > 2. Reduce that number modulus (2*31)-2
> > 3. Add 1.
>
> > Charles
>
> You are missing the point.
>
> It is true in the present instance that any non zero value less than
> 2*31 is a valid seed;

less than (2*31)-1

> but if you simply choose a new seed at random
> there is a risk that you will simply be generating the same stream of
> random numbers you used in a previous experiment shifted by a bit.

That an inevitable consequence of using a deterministic random number
generator, i.e. one for which the sequence depends only on the
starting point.

> This can lead to undesirable correlation between runs which can
invalidate
> subsequent statistical analysis.

That would be true if one used a method of choosing a restart point
for the random seed which is limited to a relative (relative to
2*31-1) handful of possible values. If the restart method truly chose
at random -- equal probability -- among all possible seed values, then
it would have no more tendency toward serial correlation than would
saving []RL. If you disbelieve this, that would explain the sense in
which you think I missed "the" point.

I think hashing []TS is good enough -- as opposed to the method of
counting loop iterations in a fixed short time which I remarked
earlier turned out to be even worse than I expected.

> Saving {quad}RL at the end of a run and restoring it at the beginning of
> the next is hardly a major housekeeping issue.

Given the nature of my application the mechanism would be tedious
enough that I prefer not to bother. I don't force my decision on
anyone else.

Charles




 12 Posts in Topic:
picking a new random seed
Charles Brenner <cbren  2008-01-26 17:01:18 
Re: picking a new random seed
Sam Sirlin <swsirlin@[  2008-01-26 17:47:00 
Re: picking a new random seed
"Curtis A. Jones&quo  2008-01-27 13:33:38 
Re: picking a new random seed
Phil Last <phil.last@[  2008-01-27 15:01:01 
Re: picking a new random seed
"Curtis A. Jones&quo  2008-01-28 09:09:42 
Re: picking a new random seed
Phil Last <phil.last@[  2008-01-28 10:08:42 
Re: picking a new random seed
rbe <bernecky@[EMAIL P  2008-01-29 06:15:33 
Re: picking a new random seed
Charles Brenner <cbren  2008-01-29 21:37:30 
Re: picking a new random seed
"James J. Weinkam&qu  2008-01-30 21:57:05 
Re: picking a new random seed
"jk" <*axy*@  2008-01-30 23:06:17 
Re: picking a new random seed
Jane Sullivan <jane@[E  2008-01-31 07:13:48 
Re: picking a new random seed
Charles Brenner <cbren  2008-02-03 13:59:35 

Post A Reply:
  Go here to Signup

AddThis Feed Button


About - Advertising - Contact - Frequently Asked Questions - Privacy Policy - Terms of Use - Signup

Contact
tan12V112 Fri May 16 10:56:35 CDT 2008.