Beefy Boxes and Bandwidth Generously Provided by pair Networks
"be consistent"

Comment on

( #3333=superdoc: print w/replies, xml ) Need Help??

How about this:

1) choose a weight among the weight range randomly

2) With the weight fixed, randomly distribute the weight to prefix1,prefix2 and suffix. I.e. for a weight of 8 you might get a distribution of 3,3,2 (or 3,1,4 or 0,6,2...)

3) Now randomly choose a prefix1 with the chosen weight (or none if prefix1 weight is 0). In the example that would be 3. Also select one suffix with the chosen weight (2 in the example). And finally select as many prefix2s until you have reached the chosen weight for prefix2s. Since you could get more than 3 items for prefix2, you should add a step where you combine two lesser prefixes into one (of their combined weight) until you reach 3 items.

If you still get too many prefix2s in your items, you could have higher weight prefixes more often in your prefix2-table than lower weight prefixes. For example a prefix of weight 4 would be 4 times in the table, a prefix of weight 1 only once (this is just a simple method to select higher items more often. If you don't like that, there are other methods)

In reply to Re: Algorithm Help by jethro
in thread Algorithm Help by dreadpiratepeter

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, 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, 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.
  • Log In?

    What's my password?
    Create A New User
    [Discipulus]: is here ? ;=)
    [choroba]: tkoroba ready to answer your tkuestions!

    How do I use this? | Other CB clients
    Other Users?
    Others drinking their drinks and smoking their pipes about the Monastery: (8)
    As of 2018-04-20 15:47 GMT
    Find Nodes?
      Voting Booth?