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

2130[Clip] Re: randomize number

Expand Messages
  • Eb Guenther
    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 -----

      ;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%
      ^!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.


    • Show all 23 messages in this topic