in reply to Sampling from Combination Space

I have an interesting suggestion.

To generate a sampling, you just repeat the following steps:

  1. set $sum to 0, $count to 0
  2. generate a random number $r between 1 and m
  3. add this random number to the $sum += $r
  4. if $sum <= 158, $count ++, else quit the loop

After this process, the variable $count contains the number of random number you used to reach 158, which can be considered as number of selections.

Repeat above process and you will get the satistics. Refine this a little bit and pick the right m, will give you soem good enough simulation. You have to refine this.

Here is some code to illustrate this:

use strict; use warnings; my @counts; while (1) { my $count = 0; my $sum = 0; while (1) { $sum += rand(rand(rand(rand(158))));#need to refine print "$sum\n"; ($sum <= 158) ? $count ++ : last; } $counts[$count] ++; print "choose $count\n"; sleep 1; }