[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
- sampling from two instances of a random number generator, Leo Razoumov, 2008/05/24
- Re: sampling from two instances of a random number generator, Ben Abbott, 2008/05/24
- Re: sampling from two instances of a random number generator, Jaroslav Hajek, 2008/05/25
- Re: sampling from two instances of a random number generator, Leo Razoumov, 2008/05/25
- Re: sampling from two instances of a random number generator, Leo Razoumov, 2008/05/25
- Re: sampling from two instances of a random number generator, Søren Hauberg, 2008/05/26
- Re: sampling from two instances of a random number generator, Leo Razoumov, 2008/05/27
- Re: sampling from two instances of a random number generator, David Bateman, 2008/05/27
Re: sampling from two instances of a random number generator, Francesco Potorti`, 2008/05/25