"Sheri" <silvermoonwoman@...> wrote:

>

> Not entirely sure about that calc. Would this possibly give more random results?

>

> ^!Set %n%=^$Calc(rnd(^$Calc(^%ar0% - 1)$) + 1;0)$

>

Sheri, (hello! :)

I believe that for cases where there are three or more alternatives, your suggestion would actually give the first and the last choices statistical disadvantage. For example, for an array of three elements: the range from 1.00 to 1.49, a set of only 50 possible numbers, would produce 1 (after rounding RND results with ;0); the range from 1.50 to 2.49, a set of 100 possible numbers, would give 2; and the range from 2.50 to 3.00, a set of 51 possible numbers, would result in 3. The probability in this case would be near 25%, 50% and 25% for the first, second and third alternative respectively.

CEIL that I tried rounds up to the next full integer, so each alternative gets an equal pool of "winning" possibilities: 0.01 to 1.00 = 1, 1.01 to 2.00 = 2, and 2.01 to 3.00 = 3.

But one big oopsie that I somehow didn't foresee is the fact that when RND happens to choose zero, CEIL leaves it as is, and thus instead of inserting the first alternative, the number of array elements (^%ar0%) would be pasted. Here's an approach that avoids this issue while still satisfying the statistical equality of chances:

^!Set %n%=^$Calc(FLOOR(RND(^%ar0%)+1))$