Bookmark and Share

Notice: On March 31, it was announced that Statalist is moving from an email list to a forum. The old list will shut down on April 23, and its replacement, statalist.org is already up and running.


[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

st: Random start to random number sequence


From   "Allan Reese (Cefas)" <allan.reese@cefas.co.uk>
To   <statalist@hsphsun2.harvard.edu>
Subject   st: Random start to random number sequence
Date   Tue, 17 Aug 2010 10:02:22 +0100

I looked on Statalist for a simple function to start the random number
generator with a random value and found lots of rather confusing
messages.  The Manual stresses the ability to repeat sequences from one
session to another, rather than to generate an (almost certainly for
practical purposes) unique sequence.  

The uniform() function to generate (pseudo) random numbers starts from
the same value in each Stata session unless you change the start value
with "set seed -value-", where value is an integer ([D] gen).  This is
very useful in allowing simulations to be repeatable but open to
variation: you get very different random sequences by setting the seed
to 1, 2, 3, etc.

On the other hand, you may simply require a different random sequence in
each session.  Rather than remember the seed values you have used
previously, you can use the system clock which changes every second.
This will not make the subsequent sequence any more (or less) random,
but will make each session unique.  The "code" (see -help seed- to
explain) can be displayed or saved in case you do want to reproduce a
session.

Using the clock has been suggested several time but with a complex
parsing.  Here is a simple program that can be added to your ado
library:

program define randomseed
   version 7
   local seed = clock( c(current_time), "hms" )
   set seed  `seed'
   di "Clock based seed = " c(seed)
end     


R Allan Reese
Senior statistician, Cefas
The Nothe, Weymouth DT4 8UB 

Tel: +44 (0)1305 206614 -direct
Fax: +44 (0)1305 206601 

www.cefas.co.uk 


***********************************************************************************
This email and any attachments are intended for the named recipient only.  Its unauthorised use, distribution, disclosure, storage or copying is not permitted.  If you have received it in error, please destroy all copies and notify the sender.  In messages of a non-business nature, the views and opinions expressed are the author's own and do not necessarily reflect those of the organisation from which it is sent.  All emails may be subject to monitoring.
***********************************************************************************


*
*   For searches and help try:
*   http://www.stata.com/help.cgi?search
*   http://www.stata.com/support/statalist/faq
*   http://www.ats.ucla.edu/stat/stata/


© Copyright 1996–2014 StataCorp LP   |   Terms of use   |   Privacy   |   Contact us   |   Site index