MathGroup Archive 2005

[Date Index] [Thread Index] [Author Index]

Search the Archive

Re: SeedRandom and $SessionID

  • To: mathgroup at smc.vnet.net
  • Subject: [mg58629] Re: SeedRandom and $SessionID
  • From: Jean-Marc Gulliet <jeanmarc.gulliet at gmail.com>
  • Date: Sun, 10 Jul 2005 16:51:53 -0400 (EDT)
  • Organization: The Open University, Milton Keynes, England
  • References: <dao1jp$b6d$1@smc.vnet.net>
  • Sender: owner-wri-mathgroup at wolfram.com

Kerry Kim wrote:
> Hi Everyone,
> 
> I'm doing some Monte-Carlo simulations on a cluster.  Since by default 
> the random number seed is based on the system time, I sometimes get the 
> same seed being used in multiple Kernels if they're launched 
> simultaneously from a shell script (something to avoid).  Is there any 
> danger in using $SessionID as the random number seed?  Also, does anyone 
> know the bounds on $SessionID (compared to the bounds on the random 
> number seed) are and whether the processID is included in the 
> calculation of $SessionID?  Alternatively, has anyone worked out a good 
> way to seed the random number generator in Mathematica?
> 
> Thank you!
> -Kerry Kim
> 
Hi Kerry,

Since *SeedRandom* can use a string as parameter, you can build a seed 
with a combination of absolute time and specific machine/session/process 
information. For example

In[1]:=
$MachineID

Out[1]=
"6102-07761-35533"

In[2]:=
$ProcessID

Out[2]=
2692

In[3]:=
$SessionID

Out[3]=
21823539906304522724

In[4]:=
seed = StringJoin[$MachineID, ToString[$SessionID],
    ToString[$ProcessID], ToString[AbsoluteTime[]]]

Out[4]=
"6102-07761-35533218235399063045227242692             \
         9\n3.3300079210000000 10"

In[5]:=
SeedRandom[seed]

In[6]:=
Random[]

Out[6]=
0.38715300837241634

Hope this helps,
/J.M.


  • Prev by Date: Re: Complement replacement
  • Next by Date: Re: Complement replacement
  • Previous by thread: Re: FrameTicks bug (SUMMARY)
  • Next by thread: Planetarium.m