Using the example of two 6-sided dice. If we set a limit of 10 for the sum, then some values will be rejected. Which I think is analogous to this problem. Accumulating the frequency for each value by simply rejecting those over our limit still gives a flat distribution:

#! perl -slw use strict; use List::Util qw[ sum ]; my %stats; for( 1 .. $ARGV[ 0 ] || 1e3 ) { my @dice = map 1 + int( rand 6 ), 1 .. 2; next if sum( @dice ) > 10; ++$stats{ "@dice" }; } my $mean = sum( values %stats ) / scalar values %stats; printf "%12s %d dev( %d )\n", $_, $stats{ $_ }, abs( $stats{ $_ } - $mean ) for map unpack( 'x[C2] A*', $_ ), sort map pack( 'C2 A*', ( reverse split( ' ', $_ ) ), $_ ), keys %stats; __END__ C:\test>junk7 1e6 1 1 27534 dev( 247 ) 2 1 27640 dev( 141 ) 3 1 27742 dev( 39 ) 4 1 27878 dev( 96 ) 5 1 28161 dev( 379 ) 6 1 27556 dev( 225 ) 1 2 28018 dev( 236 ) 2 2 27426 dev( 355 ) 3 2 27650 dev( 131 ) 4 2 28099 dev( 317 ) 5 2 27949 dev( 167 ) 6 2 27607 dev( 174 ) 1 3 27752 dev( 29 ) 2 3 28033 dev( 251 ) 3 3 27767 dev( 14 ) 4 3 27730 dev( 51 ) 5 3 27802 dev( 20 ) 6 3 27760 dev( 21 ) 1 4 27791 dev( 9 ) 2 4 28065 dev( 283 ) 3 4 27894 dev( 112 ) 4 4 27487 dev( 294 ) 5 4 27778 dev( 3 ) 6 4 27935 dev( 153 ) 1 5 27708 dev( 73 ) 2 5 27668 dev( 113 ) 3 5 27854 dev( 72 ) 4 5 27810 dev( 28 ) 5 5 27654 dev( 127 ) 1 6 27600 dev( 181 ) 2 6 27700 dev( 81 ) 3 6 28029 dev( 247 ) 4 6 27717 dev( 64 )

Whether a flat distribution is correct for this application is GrandFather's call. But even if some other distribution (poisson or whatever), is required, it would be much easier to arrive at that once you have a generator that produces a known distribution. I'm also unsure how you extend those other distributions to 4 or more dimensions?


Examine what is said, not who speaks -- Silence betokens consent -- Love the truth but pardon error.
"Science is about questioning the status quo. Questioning authority".
In the absence of evidence, opinion is indistinguishable from prejudice.
"Too many [] have been sedated by an oppressive environment of political correctness and risk aversion."

In reply to Re^5: Need technique for generating constrained random data sets by BrowserUk
in thread Need technique for generating constrained random data sets by GrandFather

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



  • 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:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.