Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl Monk, Perl Meditation

comment on

( #3333=superdoc: print w/replies, xml ) Need Help??
A sum of random numbers will be more bell-shaped than a single random number. Hence, rolling 2 6-sided dice will yield more sevens on average than rolling an 11-sided die numbered from 2 to 12. The more dice, the more heavily weighted toward the center of the range you'll be.

For your 6-21 example, there are 16 numbers that need to be covered. You could roll two 16-sided dice, add them together, and divide by two to get a center-weighted result in the desired range.

Here's a little program to demonstrate the distribution:

my $range=16; my $low_end=6; my %freq = (); for (1..1000) { my $result = int((rand($range)+rand($range))/2)+$low_end; ++$freq{$result}; } print "$_: $freq{$_}\n" for (sort {$a<=>$b} keys %freq); __END__ 6: 10 7: 35 8: 44 9: 52 10: 61 11: 77 12: 107 13: 109 14: 118 15: 111 16: 95 17: 46 18: 49 19: 57 20: 24 21: 5

The PerlMonk tr/// Advocate

In reply to Re: Efficient ways of storing a data set for random access by Roy Johnson
in thread Efficient ways of storing a data set for random access by dthacker

Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post; it's "PerlMonks-approved HTML":

  • Are you posting in the right place? Check out Where do I post X? to know for sure.
  • Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
    <code> <a> <b> <big> <blockquote> <br /> <dd> <dl> <dt> <em> <font> <h1> <h2> <h3> <h4> <h5> <h6> <hr /> <i> <li> <nbsp> <ol> <p> <small> <strike> <strong> <sub> <sup> <table> <td> <th> <tr> <tt> <u> <ul>
  • Snippets of code should be wrapped in <code> tags not <pre> tags. In fact, <pre> tags should generally be avoided. If they must be used, extreme care should be taken to ensure that their contents do not have long lines (<70 chars), in order to prevent horizontal scrolling (and possible janitor intervention).
  • Want more info? How to link or How to display code and escape characters are good places to start.
Log In?

What's my password?
Create A New User
Domain Nodelet?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others taking refuge in the Monastery: (2)
As of 2023-06-02 07:28 GMT
Find Nodes?
    Voting Booth?

    No recent polls found