2006-10-31 15:23:16 +00:00
|
|
|
\section random random - generate random number
|
2005-09-20 13:31:55 +00:00
|
|
|
|
|
|
|
\subsection random-synopsis Synopsis
|
2014-08-01 12:25:41 +00:00
|
|
|
\fish{synopsis}
|
2016-11-28 20:57:58 +00:00
|
|
|
random
|
|
|
|
random SEED
|
|
|
|
random START END
|
|
|
|
random START STEP END
|
|
|
|
random choice [ITEMS...]
|
2014-08-01 02:37:32 +00:00
|
|
|
\endfish
|
2005-09-20 13:31:55 +00:00
|
|
|
|
|
|
|
\subsection random-description Description
|
|
|
|
|
2016-11-28 20:57:58 +00:00
|
|
|
`RANDOM` generates a pseudo-random integer from a uniform distribution. The
|
|
|
|
range (inclusive) is dependent on the arguments passed.
|
|
|
|
No arguments indicate a range of [0; 32767].
|
|
|
|
If one argument is specified, the internal engine will be seeded with the
|
|
|
|
argument for future invocations of `RANDOM` and no output will be produced.
|
|
|
|
Two arguments indicate a range of [START; END].
|
|
|
|
Three arguments indicate a range of [START; END] with a spacing of STEP
|
|
|
|
between possible outputs.
|
|
|
|
`RANDOM choice` will select one random item from the succeeding arguments.
|
2015-12-29 04:31:12 +00:00
|
|
|
|
2016-11-28 20:57:58 +00:00
|
|
|
Note that seeding the engine will NOT give the same result across different
|
|
|
|
systems.
|
2014-08-19 12:41:23 +00:00
|
|
|
|
2016-11-28 20:57:58 +00:00
|
|
|
You should not consider `RANDOM` cryptographically secure, or even
|
|
|
|
statistically accurate.
|
2005-09-20 13:31:55 +00:00
|
|
|
|
|
|
|
\subsection random-example Example
|
|
|
|
|
2016-11-28 20:57:58 +00:00
|
|
|
The following code will count down from a random even number between 10 and 20 to 1:
|
2014-08-01 02:37:32 +00:00
|
|
|
\fish
|
2016-11-28 20:57:58 +00:00
|
|
|
for i in (seq (random 10 2 20) -1 1)
|
2014-08-01 02:37:32 +00:00
|
|
|
echo $i
|
2005-09-20 13:31:55 +00:00
|
|
|
end
|
2014-08-01 02:37:32 +00:00
|
|
|
\endfish
|
2016-11-28 20:57:58 +00:00
|
|
|
And this will open a random picture from any of the subdirectories:
|
|
|
|
\fish
|
|
|
|
open (random choice **jpg)
|
|
|
|
\endfish
|