help-octave
[Top][All Lists]
Advanced

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

Re: sampling from two instances of a random number generator


From: Francesco Potorti`
Subject: Re: sampling from two instances of a random number generator
Date: Sun, 25 May 2008 22:46:16 +0200

>I need to sample from several instances of a random number generator
>in the same program. Apparently, Octave does not let me do it. It
>seems as though that "rand" has only one global state. The best advice
>from the manual  is to save/restore rand state with
> v = rand("state")
> rand("state", v)
>
>Since I have to draw only one number at a time from each RNG millions
>of time this can quickly become a nuisance. Also, it is plain ugly!

Why?  You just define a function that takes the generator identifier (a
number) as its only argument and returns a fresh random number from that
generator.  The function contains a persistent matrix (or cell array)
with the states of all your generators.  You start with a random matrix,
or a fixed matrix.

>Octave is object oriented, right? Why not to have a RNG constructor
>rng1= RNGuniform(seed)
>...
>sample= rng1.get()

With the sulution I suggest above it would be
 sample=multrng(n)

-- 
Francesco Potortì (ricercatore)        Voice: +39 050 315 3058 (op.2111)
ISTI - Area della ricerca CNR          Fax:   +39 050 315 2040
via G. Moruzzi 1, I-56124 Pisa         Email: address@hidden
(entrance 20, 1st floor, room C71)     Web:   http://fly.isti.cnr.it/


reply via email to

[Prev in Thread] Current Thread [Next in Thread]