Paul Kienzle wrote:
On Feb 22, 2007, at 7:29 PM, Paul Kienzle wrote:
On Feb 22, 2007, at 11:46 AM, David Bateman wrote:
I haven't tried to convert the functions geornd,
Octave uses the following; it would be hard to beat:
rnd(k) = floor (log (rand (size (k))) ./ log (1 - p(k)));
On second thought,
rnd = floor(-rande(n)) ./ log(1-p)
is 2x faster.
Are you sure its not the reverse
octave:3> function rnd = geornd2(p,varargin), rnd =
floor(-rande(varargin{:})) ./ log(1-p); endfunction
octave:4> tic; b0 = geornd(3,1,1e7); toc
Elapsed time is 1.643173 seconds.
octave:5> tic; b1 = geornd2(3,1,1e7); toc
Elapsed time is 3.176453 seconds.