## Re: Searching variables with regex?

Expand Messages
• ... 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
Message 1 of 35 , Oct 5, 2010
"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))\$
• See? There s always someone ready to apply the rules even when I thought I was doing something harmless?!! sry bout that.. point taken. will visit
Message 35 of 35 , Oct 11, 2010
See? There's always someone ready to apply the rules even when I thought I was doing something harmless?!! <ahem> sry 'bout that.. point taken. will visit over there.....

--- In ntb-clips@yahoogroups.com, Axel Berger <Axel-Berger@...> wrote:
>
> Paul wrote:
> > I only stiffly object to copied work when it is purported to be
> > ones own work. In the early stages of professional development
> > I advocate reprimand and retraining.
>
> This is beginning to drift off the topic od clips, My answer certainly
> is, which is why I just posted it to the off-topic list.
>
> Axel
>
Your message has been successfully submitted and would be delivered to recipients shortly.