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:18:22 +0200

søn, 25 05 2008 kl. 14:32 -0400, skrev Leo Razoumov:
> I understand that for the sake of backward compatibility existing
> "rand" API has to be stable and cannot be changed. But how difficult
> would it be to create an alternative RNG mechanism that properly
> handles RNG state within RNG object?? Even "plain C" GSL handles RNG
> states in a proper object oriented way.

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...




reply via email to

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