It won't be exactly a log 10 distribution, but rand()**2 * $max would probably be close to what you're looking for.
For example:
$rand_max = 1025;
sub my_rand{
$rnd = rand;
return int($rnd*$rnd * $rand_max);
}
@a = ();
for(1..100000) {
$n = my_rand();
$a[$n]++;
}
$i = 1;
while($i <= 1024) {
print "$i: ", $a[$i], $/;
$i = $i*2;
}
will produce a distribution similar to this:
1: 1338
2: 913
4: 718
8: 526
16: 397
32: 280
64: 195
128: 137
256: 99
512: 65
1024: 42
If the curve is too steep (or not steep enough), you can adjust the exponent to 1.5, or 2.5 etc., instead of 2.
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.