Next: ONCE and AGAIN, Previous: Statement Identifiers, Up: Syntax [Index]
INTERCAL-72 | C-INTERCAL | CLC-INTERCAL | J-INTERCAL |
---|---|---|---|
yes | all versions | version 0.02+ | all versions |
It’s possible to specify that a command should be run only a
certain proportion of the time, at random. This is a rarely used
feature of INTERCAL, although it is the only way to
introduce randomness into a program. (The C-INTERCAL
compiler approximates this with pseudorandomness.) An execution chance
specification comes immediately after the statement identifier, but
before the rest of the statement, and consists of a double-oh-seven
(%
) followed by an integer from 1 to 99 inclusive, written
in decimal; this gives the percentage chance of the statement running.
The execution chance only acts to prevent a statement running when it
otherwise would have run; it cannot cause a statement that would
otherwise not have run to run. For instance, the statement DO %40
WRITE OUT #1
has a 40% chance of writing out
‘I’, but the statement DON'T %40 WRITE
OUT #1
has no chance of writing out I
or anything
else, because the N'T
prevents it running and the
double-oh-seven cannot override that.