MathGroup Archive 2006

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

Search the Archive

Re: random inside module

  • To: mathgroup at smc.vnet.net
  • Subject: [mg67735] Re: random inside module
  • From: Jens-Peer Kuska <kuska at informatik.uni-leipzig.de>
  • Date: Thu, 6 Jul 2006 06:52:29 -0400 (EDT)
  • References: <e8ft72$q6g$1@smc.vnet.net>
  • Sender: owner-wri-mathgroup at wolfram.com

Hi,

with

SeedRandom[n] resets the pseudorandom number generator, using the 
integer n as a seed.

and you may set the same seed every time you call the Module[].

Regards
   Jens

Arkadiusz Majka wrote:
> DearAll,
> 
> The code below works fine
> 
> ClearAll[list, maja, a]
> maja[T_] := Module[{i, p = 2}, list[0_] = {1, 2, 3};
>     a[i_] := 0 /; Mod[i, p] != 0;
>     a[i_] := Random[Integer, {1, 10}] /; Mod[i, p] == 0;
>     list[i_] := list[i] = Prepend[list[i - 1], a[i]]; list[T]]
> 
> and may have an output
> 
> Table[maja[i],{i,...}]
> 
> {{1,2,3},{0,1,2,3},{9,0,1,2,3},{0,9,0,1,2,3},{7,0,9,0,1,2,3},...}
> 
> we see that maja[i] differs from maja[i-1] that one element is added in
> front of the list (0 or Random(1,10) )
> 
> Now I want to manipulate p , so I create Module
> 
> ClearAll[list, maja, a]
> maja[T_, p_] := Module[{i, list, a}, list[0_] = {1, 2, 3};
>     a[i_] := 0 /; Mod[i, p] != 0;
>     a[i_] := Random[Integer, {1, 10}] /; Mod[i, p] == 0;
>     list[i_] := list[i] = Prepend[list[i - 1], a[i]]; list[T]]
> 
> 
> The problem is now that, because I had to put 'list' within {}, the
> program is generating always new random numbers and I get
> 
> {1,2,3},{0,1,2,3},{4,0,1,2,3},{0,3,0,1,2,3},{7,0,6,0,1,2,3},....
> 
> when I remove 'list' from {} sampling is ok but I lose the possibility
> of manipulating p .
> 
> What to do?
> 
> The general problem is : how to deal with random functions inside
> module?
> 
> Please, help!
> 
> Arek
> 


  • Prev by Date: RE: Incomplete Gamma function
  • Next by Date: Re: Plot Question
  • Previous by thread: Re: random inside module
  • Next by thread: Re: Hexagonal indexing?