$ for J in {0,1,2,3,4,5,6,7,8,9}{0,1,2,3,4,5,6,7,8,9}{0,1,2,3,4,5,6,7,8,9}; do ./pm_sample_lines_from_file.pl a_million_lines 25 >t.$J; done
####
#!/usr/bin/perl
#
# pm_sample_histo_test.pl
#
# Make a brief histogram to see if there's any obvious bias in the sampler.
# Assumes you're sampling from a file containing a million lines, each of
# which contains just the line number.
#
use 5.10.1;
use strict;
use warnings;
my %H;
for my $FName (@ARGV) {
print "-- $FName --\n";
open my $FH, '<', $FName or die "can't open $FName\n";
while (<$FH>) {
next if /^random/;
my $I = int $_/10000;
$H{$I}++;
}
}
my $max=0;
for (keys %H) { $max = $H{$_} if $H{$_} > $max; }
for my $I (0 .. 99) {
my $bar = substr('*' x int(50 * ($H{$I}/$max)) . ' 'x50, 0, 50);
if ($I > 1 and $I < 98) {
my $avg;
my $sum = 0;
$sum += $H{$_} for $I-2 .. $I+2;
$avg = $sum/5;
substr($bar,int(50 * ($avg/$max)),1)='+';
}
printf "% 3u: (% 3u) %s\n", $I, $H{$I} // 0, $bar;
}
##
##
$ ./pm_sample_histo_test.pl t.*
0: (321) **************************************************
1: (290) *********************************************
2: (290) *********************************************+
3: (291) *********************************************+
4: (281) ******************************************* +
5: (307) *********************************************+*
6: (290) ********************************************+
7: (283) ********************************************+
8: (280) ******************************************* +
9: (283) ********************************************+
10: (309) ********************************************+***
11: (287) *******************************************+
12: (267) ***************************************** +
13: (253) *************************************** +
14: (292) *****************************************+***
15: (257) **************************************** +
16: (278) ******************************************+
17: (254) *************************************** +
18: (286) ******************************************+*
19: (250) ************************************** +
20: (291) ******************************************+**
21: (277) ******************************************+
22: (270) ******************************************+
23: (262) **************************************** +
24: (261) ****************************************+
25: (263) ***************************************+
26: (246) ************************************** +
27: (237) ************************************ +
28: (261) ***************************************+
29: (245) ************************************** +
30: (265) ***************************************+*
31: (267) ***************************************+*
32: (234) ************************************ +
33: (269) ****************************************+
34: (252) *************************************** +
35: (272) ****************************************+*
36: (259) ****************************************+
37: (243) ************************************* +
38: (266) ***************************************+*
39: (237) ************************************ +
40: (259) ***************************************+
41: (256) ***************************************+
42: (249) ************************************** +
43: (269) ****************************************+
44: (274) *****************************************+
45: (266) ****************************************+
46: (267) ***************************************+*
47: (229) *********************************** +
48: (233) ************************************ +
49: (265) ***************************************+*
50: (247) ************************************** +
51: (281) ****************************************+**
52: (243) ************************************* +
53: (249) ************************************** +
54: (249) ************************************** +
55: (251) **************************************+
56: (262) *************************************+**
57: (228) *********************************** +
58: (217) ********************************* +
59: (262) *************************************+**
60: (260) **************************************+*
61: (225) *********************************** +
62: (263) ****************************************+
63: (297) ****************************************+*****
64: (271) ******************************************+
65: (250) ************************************** +
66: (275) *****************************************+
67: (267) ***************************************+*
68: (260) ***************************************+
69: (224) ********************************** +
70: (256) **************************************+
71: (241) ************************************* +
72: (257) ***************************************+
73: (256) ***************************************+
74: (257) ***************************************+
75: (246) ************************************** +
76: (267) ***************************************+*
77: (267) **************************************+**
78: (232) ************************************ +
79: (239) ************************************* +
80: (252) **************************************+
81: (269) **************************************+**
82: (234) ************************************ +
83: (239) ************************************* +
84: (240) ************************************* +
85: (259) ***************************************+
86: (290) ****************************************+****
87: (249) ************************************** +
88: (256) ***************************************+
89: (235) ************************************ +
90: (242) ************************************* +
91: (261) **************************************+*
92: (245) **************************************+
93: (245) ************************************** +
94: (248) **************************************+
95: (274) ***************************************+**
96: (230) *********************************** +
97: (263) **************************************+*
98: (241) *************************************
99: (236) ************************************