Random #s
Dave Cragg
dcragg at lacscentre.co.uk
Thu Jan 27 08:35:14 EST 2005
On 27 Jan 2005, at 11:25, Mark Smith wrote:
> How about something like:
>
> repeat until the number of items in tRnum = 5
> put random(10) into tRand
> if tRand is not among the items of tRnum then put tRand & comma after
> tRnum
> end repeat
>
Although I'm sure this is fine in practice, this kind of solution
always makes me a little nervous. In theory, it could take for ever to
find a unique set of numbers. While my testing shows it never takes
longer than a millisecond, Murphy's law says that the first time you
put it into an application, it will take three days. :)
For the nervous ninnies like myself, this function should be more
consistent:
function any5from10
put "1,2,3,4,5,6,7,8,9,10" into tList
sort items of tList by random(1000)
return item 1 to 5 of tList
end any5from10
Cheers
Dave
More information about the use-livecode
mailing list