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

Re: Searching variables with regex?

Expand Messages
  • Eb
    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,
    Message 1 of 35 , Oct 6, 2010
      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

      --- In ntb-clips@yahoogroups.com, "diodeom" <diomir@...> wrote:
      >
      > I wrote:
      > >
      > > ^!Set %n%=^$Calc(FLOOR(RND(^%ar0%)+1))$
      > >
      >
      > If of interest to anyone, I utilized the following makeshift clip to better test "fairness" of various randomizing takes:
      >
      > ;Number of random numbers to generate +1
      > ^!Set %i%=1001
      > ;Number of alternatives (array elements), min 2/max 8
      > ^!Set %alt%=3
      > :Rand
      > ^!Dec %i%
      > ^!If ^%i%=0 Count
      > ;Variants of getting random numbers
      > ^!Set %method%=^$Calc(FLOOR(RND(^%alt%)+1))$
      > ;^!Set %method%=^$Calc(RND(^$Calc(^%alt%-1)$)+1;0)$
      > ;^!Set %method%=^$Calc(CEIL(RND(^%alt%)))$
      > ^!Append %rnd%=^%method%
      > ^!Goto Rand
      > :Count
      > ^!Inc %i%
      > ^!If ^%i%>^%alt% Done
      > ^!Set %h%=^$StrCount(^%i%;^%rnd%;0;0)$
      > ^!Append %res%=Alt ^%i%: ^%h% hits
      > ^!Append %res%=, ^$Calc(^%h%/^$StrSize(^%rnd%)$*100;2)$%^%nl%
      > ^!Goto Count
      > :Done
      > ^!Info [L]^%res%
      > ^!Set %i%=; %alt%=; %method%=; %rnd%=; %h%; %res%=
      >
      > For a more accurate illustration, this obviously could be furthered to average data collected from multiple runs.
      >
    • Paul
      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.