Loading ...
Sorry, an error occurred while loading the content.

21103Re: Searching variables with regex?

Expand Messages
  • diodeom
    Oct 7, 2010
      Cool; I wish I had thought of it here, Eb -- directly incrementing results in an array. And it shaves a respectable half a second of almost three consumed by the original on my comp. Another advantage (even though it evidently wasn't my concern when putting together this impromptu clip) is that your approach is not limited to just a few alternatives. The variable %count% could be made universal for any %alt% value with e.g.:

      ^!SetArray %count%=0^$StrFill(^%nl%0;^$Calc(^%alt%-1)$)$

      For me a ten-cycle set of 10,000 generated random numbers (after running their averages) gave between either of the three %alt% alternatives a maximum average variance of 78.5 "hits" or 0.785%. The same done for just 100 numbers produced -- as expected -- a much larger max spread of 3.6%. Fair by me. I'd probably freak and question *randomness* if the statistical expectations anchored in infinity were met on the dot at low quantities/iterations.

      Anyway, this (I'd suggest: overkill, to say the least) tester was only meant to help me illustrate more radical favoritism (or lack thereof) of different takes. I appreciate your contribution regardless of this context.

      --- In ntb-clips@yahoogroups.com, "Eb" <ebbtidalflats@...> wrote:
      > Hi Diodem,
      > That's a nifty utility, but I couldn't resist changing it a bit, to make the counting more efficient:
      > ;loop counter, Num random numbers to generate, range of numbers
      > ^!Set %i%=0; %max%=5001; %alt%=3
      > ^!SetListDelimiter ^%nl%
      > ^!SetArray %count%=0^%nl%0^%nl%0
      > :Rand
      > ^!Inc %i%
      > ^!Set %method%=^$Calc(INT(RND(^%alt%)+1))$
      > ^!Inc %count^%method%%
      > ^!If ^%i%<^%max% Rand
      > :Done
      > ^!Info [L]^%count%
      > ^!ClearVariables
      > I increased the iterations to improve the accuracy, but the error I got was still in the +/- 2% range.
      > Cheers
      > Eb
    • Show all 35 messages in this topic