#! perl -slw
use strict;
use Data::Dump qw[ pp ];
{
my @x = (0x00011011) x 24;
my $x = 0;
sub srand8 {
$x = $_[0] % 24;
}
sub rand8{
$x = ++$x % 24;
$x[ $x ] = ( $x[ $x ] * 33 + 251 ) & 255;
return $x[ $x ];
}
}
our $L //= 1e4;
our $S //= 1;
srand8( $S );
my $s = '';
$s .= pack 'C*', map rand8(), 1 .. 256 for 1 .. ($L/256+1);
print length $s;
$s =~ m[(.{256}).*?(\1)]sm
and print "Sequence at [ $-[1], $-[1] ] repeats at [ $-[2], $+[2]
+]";
__END__
C:\test>rand8 -S=1
10240
Sequence at [ 0, 0 ] repeats at [ 6144, 6400 ]
C:\test>rand8 -S=2
10240
Sequence at [ 0, 0 ] repeats at [ 6144, 6400 ]
C:\test>rand8 -S=3
10240
Sequence at [ 0, 0 ] repeats at [ 6144, 6400 ]
C:\test>rand8 -S=4
10240
Sequence at [ 0, 0 ] repeats at [ 6144, 6400 ]
C:\test>rand8 -S=5
10240
Sequence at [ 0, 0 ] repeats at [ 6144, 6400 ]
C:\test>rand8 -S=255
10240
Sequence at [ 0, 0 ] repeats at [ 6144, 6400 ]
That 6144 period could probably be improved upon with some time spent tweaking the constants, but it is hardly over-complicated.
Now, you may have a point if the OP was generating all the passwords he may ever require in his life, in a single run of the program.
Okay. Half way there. :)
That is what I assumed he was doing. I felt (still feel) that was his intent from reading the OP. But, you might be right that he intends generating them piecemeal. Or on-demand.
Using the 32-bit MT, as you've said, there are 2**32 starting points. That's 4e9 starting points into a non-repeating sequence of 4e6001.
Assuming he allows it to self-seed -- no srand() -- even if perchance two of his runs picked adjacent seed-points in the sequence, on average, he'd have to generate 4e6001 / 4e9 = 1e5992 rands before the two sub-sequences would overlap.
So, (ignoring the birthday paradox, imperfect PRNG etc. for a moment), for him to get a dup, he would have run his program 2**32 times and pick exactly 1 sequence each time. But if he generates 10 each time, that's 10 * 2**32 sequences before he gets a dup.
With the rise and rise of 'Social' network sites: 'Computers are making people easier to use everyday'
Examine what is said, not who speaks -- Silence betokens consent -- Love the truth but pardon error.
"Science is about questioning the status quo. Questioning authority".
|