Random #'s
Rob Cozens
rcozens at pon.net
Fri Jan 28 12:48:36 EST 2005
Hi Dwane,
> > 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?
function uniqueRandomNumberList listEntryCount, maxListNumber -- You would
pass "5,10"
if listEntryCount < 1 then return empty
put empty into numberList
put empty into returnValue
repeat with x = 1 to maxListNumber
put x&return after numberList
end repeat
repeat
get the random of maxListNumber
put line it of numberList after returnValue
delete line it of numberList
subtract 1 from listEntryCount
if listEntryCount < 1 then return returnValue
put comma after returnValue
subtract 1 from maxListNumber
end repeat
end uniqueRandomNumberList
More information about the use-livecode
mailing list