in reply to Re: Rolling For Initiative
in thread Rolling For Initiative
If I understand you correctly, this would require a recalculation of the @weights and $total after each pick in order to avoid getting the same pick repeatedly.
The trick in this particular question is that every choice must be picked once, and only the order is important.
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^3: Rolling For Initiative
by BrowserUk (Patriarch) on Dec 19, 2008 at 20:03 UTC | |
this would require a recalculation of the @weights and $total after each pick in order to avoid getting the same pick repeatedly Yes, but: So, to pick them all in a random order, you pick the first, subtract its weight from the total, set it weight to 0 and pick again. Repeat for N:
Putting it all together you get:
I just spent a couple of hours trying to work out how to demonstrate that this results in a properly weighted distribution, but it's beyond me today. But by cherry picking a couple of runs, I think you can see it at work: In this run you can see that ship 1 has a much lower weighting whilst the other three are very similar. With the result that the first ships 0,2 & 3 are pretty evenly distributed in the first 3 places, and ship 1 is (almost) always picked last:
In this run, ship 3 is weighted roughly twice ship 1 which is roughly twice ship 2; whilst ship 0 is almost not there. With the result that the first two picks are mostly 1s and 3s; the 3rd pick is mostly 2s and the last pick mostly 0s:
If any of the math gurus want to show me how to check the distributions arithmetically, I'm all ears :) Also, I think the big-O rating is: O( 2n + n(n-1)/4 ). Can anyone verify that for me? 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.
| [reply] [d/l] [select] |
by eric256 (Parson) on Dec 19, 2008 at 23:45 UTC | |
Nothing to add but a perl6 version that currently works under Rakudo
___________ Eric Hodges | [reply] [d/l] |
by kennethk (Abbot) on Dec 19, 2008 at 23:17 UTC | |
| [reply] [d/l] |