Name
random number
Synopsis
generate random number
generate random number
Generates a random number. By default, this is a real between 0 and 1, but you can specify a different upper bound or both bounds. If every number you specify is an integer, the result is an integer, which could be either of the bounds; otherwise it is a real. You can seed the generator to get it started; this is useful for generating a fixed pseudo-random sequence.
Example
random number
set L to {}
repeat 10 times
if (random number 1) as boolean then
set end of L to "heads"
else
set end of L to "tails"
end if
end repeat
L -- {"heads", "tails", "heads", "heads", "heads",
"tails", "heads", "heads", "heads", "heads"}
Get AppleScript: The Definitive Guide, 2nd Edition now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.