Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl Monk, Perl Meditation

Re: Algorithm Help

by jethro (Monsignor)
on Jan 18, 2010 at 19:48 UTC ( #818029=note: print w/replies, xml ) Need Help??

in reply to Algorithm 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)

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://818029]
and one hand claps...

How do I use this? | Other CB clients
Other Users?
Others meditating upon the Monastery: (2)
As of 2017-09-23 19:36 GMT
Find Nodes?
    Voting Booth?
    During the recent solar eclipse, I:

    Results (273 votes). Check out past polls.