in reply to Efficient ways of storing a data set for random access
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
|
|---|