In the following runs of the test code below, when
- $K = 1e2, $L == 2 and the random keys produced have length 2.
- $K = 1e4, $L == 4 and the keys produced have length 4.
- But when $K = 1e3, $L == 3 as expected, but the random keys have length 2?
Maybe I'm having a "thick" day today, but for the life of me, I cannot see why?
C:\test>junk0 -K=1e2
K:1e2 L:2
bd => 21537
ux => 27554
su => 32707
db => 10843
fe => 3691
aj => 23335
co => 12919
br => 21357
xw => 15950
hd => 24808
C:\test>junk0 -K=1e3
K:1e3 L:3
ne => 32586
qz => 4931
sp => 30318
tr => 9694
gl => 21489
hn => 6456
xx => 24771
sf => 3369
ro => 27152
pv => 1438
C:\test>junk0 -K=1e4
K:1e4 L:4
alof => 16425
tjtd => 16200
pief => 25920
nlly => 18027
oezy => 19290
eyzv => 5510
ztxl => 11976
yqbz => 8356
hoym => 6193
exid => 29312
The code (run as perl -s scriptname -K=nnn):
#! perl -slw
use strict;
sub rndStr{ join'', @_[ map{ rand @_ } 1 .. shift ] }
sub log10{ log( $_[0] ) / log( 10 ) }
our $K ||= 1e3;
our $L ||= log10( $K );
print "K:$K L:$L";
my %hash;
$hash{ $_ } = int rand 32767 for map{ rndStr( $L, 'a'..'z' ) } 1 .. $K
+;
print "$_ => $hash{ $_ }" for ( keys %hash )[ 0 .. 9 ];
'Unthick' me please :)
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".
In the absence of evidence, opinion is indistinguishable from prejudice.
Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
Read Where should I post X? if you're not absolutely sure you're posting in the right place.
Please read these before you post! —
Posts may use any of the Perl Monks Approved HTML tags:
- a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
| |
For: |
|
Use: |
| & | | & |
| < | | < |
| > | | > |
| [ | | [ |
| ] | | ] |
Link using PerlMonks shortcuts! What shortcuts can I use for linking?
See Writeup Formatting Tips and other pages linked from there for more info.