 2008/05/16
|
Last update 1999/02/20
TPJ: Issue_04_Randomness
- ansirand
- lfsr
- More Samples on Randomness
| Issue_04_Randomness1. ansirand
|
Download ansirand
|
#!/usr/bin/perl -w
|
|
use Config;
|
|
print "Your random number generator repeats itself after\n";
|
|
print "no more than ", 2 ** $Config{randbits}, " numbers.\n";
|
|
|
|
srand(1);
|
|
|
|
if (int(rand() * (2 ** $Config{randbits})) == 16838) {
|
|
print "Uh oh! Looks like your computer uses the ANSI example.\n";
|
|
print "I bet the next three numbers are 5758, 10113, and 17515.\n"\
|
|
;
|
|
foreach (1,2,3) {
|
|
print rand() * (2 ** $Config{randbits}), "\n";
|
|
}
|
|
}
|
| Issue_04_Randomness2. lfsr
|
Download lfsr
|
#!/usr/bin/perl -w
|
|
$seed = dec2bin(shift);
|
|
@array = split('', $seed);
|
|
|
|
@xor_bits = @ARGV;
|
|
|
|
splice(@array, 0, 31-$ARGV[0]);
|
|
print "@array\n";
|
|
while (1) {
|
|
getc();
|
|
$new_bit = 0 + $array[0];
|
|
foreach (@xor_bits[1..$#xor_bits]) {
|
|
$new_bit ^= $array[$#array - $_];
|
|
}
|
|
print pop @array;
|
|
unshift (@array, $new_bit);
|
|
}
|
|
|
|
sub dec2bin { unpack("B*", pack("N", shift)) }
|
| Issue_04_Randomness3. More Samples on Randomness
|

Last update 1999/02/20 
All Rights Reserved - (C) 1997 - 2008 by The Labs.Com |