Perl: the Markov chain saw  
PerlMonks 
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 prefix2table 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

