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

2128[Clip] Re: randomize number

Expand Messages
  • Claes Gauffin
    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

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

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

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

      ^!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%
    • Show all 23 messages in this topic