I am learning the basics of AnyDice, and have seen it used to accomplish some rather complex algorithms. I'm running into a very rudimentary problem.
Say I want to roll a pool of five ten-sided dice, find the maximum value rolled on a single die in the pool, and then count the number of times this same value appears in the pool (This seems like an odd thing to look for, but it's important as a part of a larger program I want to write.)
For example, If I rolled the values {1,4,8,9,9} on a particular toss, the result would be 2 (The maximum value, 9, appears twice).
I try to accomplish this with the following bit of code:
XROLL: 5d10
XMAX: [highest 1 of XROLL]
output [count XMAX in XROLL]
With these results:
0,59.049
1,32.805
2,7.29
3,0.81
4,0.045
5,0.001
Now, the mere fact that a count of zero appears in the results suggests something is wrong. I suspect that what is happening is that the code takes one particular toss of 5d10 when it calculates XMAX, then tosses again before finding the count of XMAX, which introduced the possibility that the XMAX found in the first toss does not even appear in the second.
What I need is some way to 'freeze' the roll and convert it to a static sequence so I can dissect the specific values found in it, and not re-roll every time I reference XROLL. Can someone confirm that AnyDice is, indeed, re-rolling every time I invoke XROLL, and suggest how to get around this?
I apologize if any of the wording is unclear or I'm not using the right terminology.
<code></code>
is only for inline code like I did just then; our code blocks use<pre><code>...
. \$\endgroup\$