random

Cubist at aol.com Cubist at aol.com
Mon Mar 13 08:36:54 EST 2006


In a message dated 3/13/06 2:49:16 AM, liamlambert <liamlambert at mac.com> 
writes:
>I have this code for a random number in 6
>fld's how do I stop the same number form appearing
>in more then one fld
   As Ms. Reichelt noted, this is one of those questions that tends to 
attract a wide variety of answers... and here is mine.

  put "1a,2a,3a,4a,5a,6a" into tFieldNames

  # build list of numbers
  put "" into DisList
  repeat with K1 = 1 to 45
    put K1 into item K1 of DisList
  end repeat

  #shuffle the list
  repeat 20
    put the random of 45 into Fred
    put item Fred ofDisList & "," before DisList
    delete item (Fred + 1) of DisList
  end repeat
  # for general-purpose scrambling, you might want to repeat this more than 
20 times.
  # in this case, however, we're only interested in the first six items. 
therefore,
  # 20 times should be (more than?) enough

  # put the first six items of DisList into the six fields
  repeat with K1 = 1 to the number of items in tFieldNames
    put item K1 of DisList into fld (item K1 of tFieldNames)
  end repeat



More information about the Use-livecode mailing list