in reply to Efficient ways of storing a data set for random access

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