MathGroup Archive 2006

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

Search the Archive

Re: strange random behavior ?

  • To: mathgroup at smc.vnet.net
  • Subject: [mg69948] Re: strange random behavior ?
  • From: Jean-Marc Gulliet <jeanmarc.gulliet at gmail.com>
  • Date: Thu, 28 Sep 2006 06:15:00 -0400 (EDT)
  • Organization: The Open University, Milton Keynes, UK
  • References: <efdjca$je$1@smc.vnet.net>

Arkadiusz.Majka at gmail.com wrote:
> Hi,
> 
> For
> 
> SeedRandom[7]
> Table[Random[Integer, {1, 6}], {5}]
> Table[Random[Integer, {1, 3}], {5}]
> 
> I get
> 
> Out[32]=
> {2,1,6,2,6}
> 
> Out[33]=
> {2,1,3,1,3}
> 
> When i repeat I obviosly get the same (magic of seedrandom)
> 
> SeedRandom[7]
> Table[Random[Integer, {1, 6}], {5}]
> Table[Random[Integer, {1, 3}], {5}]
> 
> 
> Out[32]=
> {2,1,6,2,6}
> 
> Out[33]=
> {2,1,3,1,3}
> 
> Bu when I change the range of random numbers in generation of the first
> list , say 1->2
> 
> SeedRandom[7]
> Table[Random[Integer, {2, 6}], {5}]
> Table[Random[Integer, {1, 3}], {5}]
> 
> I get
> 
> Out[35]=
> {3,2,3,6,6}
> 
> Out[36]=
> {2,2,3,1,3}
> 
> Since Seed is still the same (7), why second list is changed? (Out[36]
> does not equal to Out[33])

SeedRandom[] guarantees that the *initial* value -- the starting point 
-- used to generate a sequence of the pseudo-random number is the same 
every time the function SeedRandom is executed during a computation or 
after the kernel has been restarted.

Now, to get the same sequence of pseudo-random numbers, one must use the 
  *same* series of calls to functions like Random; that is same order, 
same parameters.

> This behavior does not take place when we do not deal with tables but
> with single elements.

Here, I am not sure what you are talking about, but using Table or not 
does not change the values generated:

In[1]:=
SeedRandom[7]
Random[Integer, {2, 6}]
Random[Integer, {2, 6}]
Random[Integer, {2, 6}]
Random[Integer, {2, 6}]
Random[Integer, {2, 6}]
Random[Integer, {1, 3}]
Random[Integer, {1, 3}]
Random[Integer, {1, 3}]
Random[Integer, {1, 3}]
Random[Integer, {1, 3}]

Out[2]=
3

Out[3]=
2

Out[4]=
3

Out[5]=
6

Out[6]=
6

Out[7]=
2

Out[8]=
2

Out[9]=
3

Out[10]=
1

Out[11]=
3

In[12]:=
SeedRandom[7]
Table[Random[Integer, {2, 6}], {5}]
Table[Random[Integer, {1, 3}], {5}]

Out[13]=
{3, 2, 3, 6, 6}

Out[14]=
{2, 2, 3, 1, 3}

Regards,
Jean-Marc


  • Prev by Date: Re: Performance comparison Mac OSX vs. Windows XP
  • Next by Date: Re: Program to calculate rational function with imbedded continued fraction
  • Previous by thread: Re: strange random behavior ?
  • Next by thread: Indefinite integration problem on ArcTanh(f(Cos))