Does anyone know where I can find the source code of such a generator?

Thanks.

Printable View

- 02-28-2010user_name_voidLooking for source code of Lagged Fibonacci generator
Does anyone know where I can find the source code of such a generator?

Thanks. - 02-28-2010Adak
Tried Google yet?

- 02-28-2010user_name_void
Yea I did tried google. They mostly have theory on LFGs. If you were able to find some code, then do share.

- 02-28-2010Adak
I don't have any, but I'll poke around.

- 02-28-2010Salem
Lagged Fibonacci generator - Wikipedia, the free encyclopedia

First hit, scroll down to "usage".

Some open source implementations - go digging! - 02-28-2010Adak
This was the best I found, outside Wikipedia:

From: What is wrong with perl's antique random number generator

Lagged Fibonacci Generator Generator

Code:`sub lfib{`

my ($m, $r, $k, $op, $seed) = @_;

my (@x, $i);

srand($seed ||time); #initialise state with rand

for (0 .. $r){

push @x, int(rand($m));

}

my $fn = "sub {

\$i = (\$i + 1) % $r;

\$x[\$i] = (\$x[\$i] $op \$x[(\$i-$k) % $r]) % $m;

(shift || 1.0) * \$x[\$i] / $m;

}\n";

return eval($fn);

}

$rand = lfib(2**48, 607, 273, '+'); #additive LFib, period 2 ** 638

$rand2 = lfib(2**64, 1279, 861, '*');#multiplicative LFib, period 2 ** 1340

print &$rand(100) . "\n" . &$rand2() ."\n";

0.0627432743424777

Maybe this should use bignum, but it seems to work without.