Random #'s

Dan Friedman dan at clearvisiontech.com
Thu Jan 27 11:50:47 EST 2005


Dwayne,

I'm sure there's a better way to do it, but how about this...

function makeRandomNumberList maxNumber
  put 0 into i
  repeat
    put random(10) into thisNum
    if thisNum is among the items of fNumbers then
      next repeat
    end if
    add 1 to i
    put thisNum into item i of fNumbers
    if i = 6 then
      exit repeat
    end if
  end repeat
  return fNumbers
end makeRandomNumberList


> Hi All, 
> I am using the following code to generate a field of 6 random numbers.
> 
> repeat 5 times --generate list of 5 random numbers between 1-10
> put random(10) & "," after tRnum
> end repeat
> delete last char of tRnum --delete last comma
> put tRnum into fld "numbers"
> 
> this works fine but some numbers are repeated in the field, e.g (1,2,3,1,5)
> How can I include only unique numbers?
> 
> Cheers......Dwayne



More information about the use-livecode mailing list