#!/usr/bin/perl

use strict;
use warnings;

my $random_state;

sub srand{
    my $seed = shift || 4357;
    my @a = ();
    for (1..10000){
	use integer;
	push @a, $seed & 0x7fffffff;
	$seed *= 69069;
    }
    $random_state = {
	offset => 0,
	array => \@a
    }
}

sub rand{
    my $range = shift || 1.0;

    ::srand(time) unless defined $random_state;

    $random_state->{offset} = ($random_state->{offset} + 1) % 10000;
    my $off = $random_state->{offset};
    my $a = $random_state->{array};

    $$a[$off] = ($$a[($off -  471) % 10000] ^
		 $$a[($off - 1586) % 10000] ^
		 $$a[($off - 6988) % 10000] ^
		 $$a[($off - 9689) % 10000]);
    return $$a[$off] * $range / (2**31);
}



#&srand(1);

my $sum = 0;

for (1..1000000){
    $sum += &rand();
    #print &rand()."\n";

}

print $sum."\n";
