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: Leo Razoumov
Subject: Re: sampling from two instances of a random number generator
Date: Sun, 25 May 2008 20:12:07 -0400

On 5/25/08, Søren Hauberg <address@hidden> wrote:
> søn, 25 05 2008 kl. 14:32 -0400, skrev Leo Razoumov:
>
>
> Probably not particular hard, so if that's what you want I'd suggest
>  that you spend some time implementing it. If you don't insists on
>  something that's object-oriented, then you might just alter the
>  following code:
>
>   function retval = myrand (sz, state)
>     rand ("state", state);
>     retval = rand (sz);
>   endfunction
>
>   N = 4;
>   states = 1:N;
>   RNGs = cell (1, N);
>   for n = 1:N
>     RNGs {n} = @(sz) myrand (sz, states (n));
>   endfor
>
>  This will give you N=4 RNGs, with initial seeds 1 to N. You can call
>  them like this:
>
>   n = 2;
>   RNGs {n} (10, 10)
>
>  to get a 10x10 matrix of random numbers from RNG number 2 (the one with
>  2 as the initial seed).
>
>  Søren
>
>  P.S. You would you want to have this stuff available in a
>  object-oriented manor? I just don't see the need for that. Would you
>  want to inherit from a RNG class or something? Otherwise
>  object-orientation just seem like a buzzword to me...
>
>

Two basic problems with this approach:
(1) Each time the whole RNG state is saved and copied. For Marsenne
Twister RNG used in Octave it is 625B. This slows things down.
(2) Still there is only one global RNG state. In  a multi-threaded
environment it can cause serious problems if several threads are
trying to update the same state. Requires explicit and careful
synchronization, etc.

--Leo--



reply via email to

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