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: Søren Hauberg
Subject: Re: sampling from two instances of a random number generator
Date: Sun, 25 May 2008 22:39:13 +0200

søn, 25 05 2008 kl. 22:28 +0200, skrev Søren Hauberg:
> søn, 25 05 2008 kl. 22:18 +0200, skrev Søren Hauberg:
> >   function retval = myrand (sz, state)
> >     rand ("state", state);
> >     retval = rand (sz);
> >   endfunction
> 
> Aarrghh, posted the wrong function. It should of course only set the
> state once. So, something like this should do:
> 
>   function retval = myrand (sz, state),
>     persistent static_state = [];
>     if (isempty (static_state))
>       static_state = state;
>       rand ("state", state);
>     endif
>     retval = rand (sz);
>   endfunction
> 
> Søren
> 
> P.S. This code isn't really tested, so you should check it before using
> it :-)

Replying once again to my own mail -- I really should learn to check
before I press the "Send" button :-)

function retval = myrand (sz, state)
  persistent static_state = [];
  if (isempty (static_state))
    static_state = state;
  endif
  rand ("state", static_state);
  retval = rand (sz);
  static_state = rand ("state");
endfunction

Something like this is probably what's needed. Anyway, as I said in the
previous mail, this code is untested, so check it before using it...

Søren



reply via email to

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