function randomNum lowerLimit,upperLimit
return random(upperLimit - lowerLimit + 1) + lowerLimit - 1
end randomNum
repeat with i = 1 to 4
put randomNum(1,52) into y
if y > 9 then
put "50" & y into x
else
put "500" & y into x
end if
if i = 1 then
put x into vCard1
end if
if i = 2 then
put x into vCard2
end if
if i = 3 then
put x into vCard3
end if
if i = 4 then
put x into vCard4
end if
end repeat
I can't figure out how to generate the 4 numbers without generating the same one more than once.
on mouseUp
local tTemp
repeat with x = 1 to 52
put x & comma after tTemp
end repeat
delete last char of tTemp -- removes trailing comma
sort items of tTemp by random(10000)
-- now take the first four numbers in tTemp
end mouseUp
put "" into tTestDupes
repeat with i = 1 to 4
put randomNum(1,52) into y
repeat while y is among the items of tTestDupes
put randomNum(1,52) into y
end repeat
put y into item (the number of items of tTestDupes +1) of tTestDupes
if y > 9 then
put "50" & y into x
else
put "500" & y into x
end if
if i = 1 then
put x into vCard1
end if
if i = 2 then
put x into vCard2
end if
if i = 3 then
put x into vCard3
end if
if i = 4 then
put x into vCard4
end if
end repeat
Just remember that random is pseudo random. But it should suffice. If you want to get a license for a casino though...
Have a look at randomseed in the dictionary.
Thanks once again Bernd! That solution seems to have worked so far! As for random, I put the milliseconds into random seed. That seems to keep it pretty random.
But your codes don't prevent the same number from being selected twice
put "1,2,3,4,5,6,....52" into randomNumbers
repeat with x = 1 to 4
put random(the number of items of randomNumbers) into randomPick
put item randomPick of randomNumbers into item x of randomList
delete item randomPick of randomNumbers
end repeat