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

[Clip] Re: randomize number

Expand Messages
  • Jody
    Hi Eb, ... My reasoning was to add the number used to it so that it would not be used again. ... a much better method sho nuff. I was in a learning process
    Message 1 of 23 , Nov 28, 1999
    • 0 Attachment
      Hi Eb,

      > Third, your reassignment of the previous results to a brand new
      > list (on restart) does not make sense.

      My reasoning was to add the number used to it so that it would
      not be used again.

      > The indirect approach I suggested to Manuel is

      a much better method sho'nuff. I was in a learning process
      myself. ;) ........and still am.

      Thanks for the help, but I still can't get it to recognize a used
      number. Ernie had pointed out to me that I was using
      SetDelimiter instead of SetListDelimter - oops! That seemed to
      help, but not a fix. Also, the RND between 1-3 returns a 4 as
      well and an occaional 9. <g>

      c ya,
      Jody

      The whole world doth err save you
      and me and even thou doest err some!

      http://www.sureword.com/sojourner
      http://www.sureword.com/mm
    • Claes Gauffin
      Hello Eb, Jody ... This is truly beautyful! Such an elegant solution to a problem which, as already remarked, is by no means trivial. One of the cases where
      Message 2 of 23 , Dec 1, 1999
      • 0 Attachment
        Hello Eb, Jody

        At 17:39 1999-11-28 -0600, you wrote:


        >
        >Here is a stand-alone, non-repeating, random DATA
        >generator clip:
        >

        This is truly beautyful! Such an elegant solution to a problem which,
        as already remarked, is by no means trivial. One of the cases where
        the manual action (drawing lots without replacement) is much simpler
        than the computerized simulation.

        Once again being a meddling busybody, I couldn't keep my sticky fingers
        away. The following only reduces the lines of code somewhat and adds a
        rudimentary input interface.

        Regards /Claes

        ^!ClearVariable %string%
        ^!ClearVariable %result%
        ^!SetListDelimiter ^p
        ^!Set %max%=^?[Maximum, if you want to pull numbers 1 - max=0]
        ^!set %items%=^?[else specify any items, separated with blanks]
        ^!If ^%max%=0 items
        ^!set %n%=1
        ^!set %string%=1

        :numbers
        ^!Inc %n%
        ^!if ^%n%>^%max% stringdone
        ^!append %string%=^%NL%^%n%
        ^!goto numbers

        :items
        ^!Set %string%=^$StrReplace(" ";"^p";"^%items%";True;False)$

        :stringdone
        ^!SetArray %List%=^%string%
        ^!Set %MaxIndex%=^%List0%

        :Again
        ^!Set %Index%=^$Calc(Int(rnd(^%MaxIndex%)+1))$
        ^!Append %result%=^%List^%Index%%^%NL%
        ^!Set %List^%Index%%=^%SPACE%
        ^!Set %List%=^$StrSort("^%List%";N;Y;N)$
        ^!SetArray %List%=^$StrDelete("^%List%";1;3)$
        ^!Dec %MaxIndex%
        ^!If ^%List0%>0 Again
        ^!InsertText ^%result%
      • Claes Gauffin
        Hello Eb, Jody It is a kind of natural law, that you are never as clear-sighted as the moment after you submit something. I realised the obvious point that the
        Message 3 of 23 , Dec 1, 1999
        • 0 Attachment
          Hello Eb, Jody

          It is a kind of natural law, that you are never as clear-sighted as the
          moment after you submit something.

          I realised the obvious point that the number of lines of code naturally is
          less important than the speed of the result. And Eb's original version is
          significantly faster than my variant, if you accumulate the result in a
          variable, rather than continously output it.

          Sorry about my butting in, Eb.

          Regards /Claes
        • Eb Guenther
          Hi Claes, ... I m not offended by someone modifying my code, especially if they then compliment me on my original . And if you look below, your version
          Message 4 of 23 , Dec 1, 1999
          • 0 Attachment
            Hi Claes,

            >It is a kind of natural law, that you are never as clear-sighted as the
            >moment after you submit something.
            >
            >I realised the obvious point that the number of lines of code naturally is
            >less important than the speed of the result. And Eb's original version is
            >significantly faster than my variant, if you accumulate the result in a
            >variable, rather than continously output it.
            >
            >Sorry about my butting in, Eb.

            I'm not offended by someone modifying my code, especially
            if they then compliment me on my original <grin>.
            And if you look below, your version gave me THE clew on
            how to get rid of those pesky 5 extra GOTOs -- that
            SPACE you put in place of the used element!

            Tack så mycket.

            So I changed the URDG (unique random data gen) as follows:

            1. End the data array with an empty element, i.e. an ";",
            just to make each element identical, if set to SPACE.
            2. Replace the hit element with a TOKEN (you used SPACE)
            (I tried a space, but got funny results because my
            data contained spaces. Then decided that this step
            required a UNIQUE token -- "#" in the sample code).
            3. The array now has a consistent pattern "#;" to delete
            in any element position.


            ;----- Start self-contained clip -----
            H="YARYDG"

            ;Yet Another Random Unique Data Generator
            ;Ver 11:22 12/1/99, Eb Guenther <ntp@...>

            ;Replace the first line with your preferred method
            ;of data Input (empty element at end!)
            ^!SetArray %List%=A;K;Q;J;T;9;8;7;6;5;4;3;2;
            ^!Set %MaxIndex%=^%List0%; %result%=Seq:
            ^!Dec %MaxIndex%
            :Again
            ^!Set %Index%=^$Calc( Int( Random( 1 ) * ^%MaxIndex% + 1 ) )$
            ^!Append %Result%=^%TAB%^%List^%Index%%
            ^!Set %List^%Index%%=#
            ^!SetArray %List%=^$StrDelete("^%List%";^$StrPos("#";"^%List%";N)$;2)$
            ^!Dec %MaxIndex%
            ^!If ^%List0%>1 Again
            ^!InsertText ^%Result%^%NL%
            ;----- End self-contained clip -----

            On my antique PC this takes about 110 mS, about 18% faster
            than my previous version! Anyone with a screamer out there
            wanna give me an incentive to get a new PC for X-mass?
            Loop the clip XX times, and divide the elapsed second by XX.
            Do I hear 10 mS? Better?

            AND the clip is simpler and easier to read.


            Regards,


            Eb
          • Jody
            Hi Eb, Manuel, and Claes, ... You did a great job! Really! I think I have it the way Manuel first requested it now with some options to make it not as
            Message 5 of 23 , Dec 1, 1999
            • 0 Attachment
              Hi Eb, Manuel, and Claes,

              > I'm not offended by someone modifying my code, especially if
              > they then compliment me on my original <grin>.

              You did a great job! <g> Really! I think I have it the way
              Manuel first requested it now with some options to make it not as
              Manuel specific. ;)

              I have the list the script picks from in an ini file now which is
              made after the Setup Clip is done. This is so a year down the
              road the used numbers, or should I say what is left is remembered
              - provided Windows doesn't eat your drive. ;->

              When the last number is used you are told to run setup again to
              build a new list. There is an option to add a wrapper start and
              end around the number. Manuel's [#nnn] is default and no wrapper
              can also be used which I suppose would be most used. Leading
              zeros are added to smaller numbers for even alignment (no option
              there >:-þ~~~). I took about 12 seconds for me to generate an
              initial list of 6600 numbers. <vbs> There is a limit of 32kb in
              an ini file so once you get to that point you will get an error
              saying cannot write to RandNum.ini. There is an option to open
              that so you can easily delete it if you want.

              It may be viewed or copied at Snatch-A-Clip. It is all the way
              at the bottom unless you use the Quick Snatch. Make sure you
              read the first few lines if you go so you know what to do with
              the html popup.

              http://www.sureword.com/notetab/html/snatchclp.html

              Have fun... Back to beta testing. :)

              Happy Clip'n!
              Jody

              http://www.sureword.com/notetab

              The NoteTab Clip List...
              mailto:Ntb-Clips-Subscribe@...
              mailto:Ntb-Clips-UnSubscribe@...
            Your message has been successfully submitted and would be delivered to recipients shortly.