2006-10-31 23:23:16 +08:00
|
|
|
\section random random - generate random number
|
2005-09-20 21:31:55 +08:00
|
|
|
|
|
|
|
\subsection random-synopsis Synopsis
|
2014-08-01 20:25:41 +08:00
|
|
|
\fish{synopsis}
|
2016-11-29 04:57:58 +08:00
|
|
|
random
|
|
|
|
random SEED
|
|
|
|
random START END
|
|
|
|
random START STEP END
|
|
|
|
random choice [ITEMS...]
|
2014-08-01 10:37:32 +08:00
|
|
|
\endfish
|
2005-09-20 21:31:55 +08:00
|
|
|
|
|
|
|
\subsection random-description Description
|
|
|
|
|
2016-11-29 04:57:58 +08: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 12:31:12 +08:00
|
|
|
|
2016-11-29 04:57:58 +08:00
|
|
|
Note that seeding the engine will NOT give the same result across different
|
|
|
|
systems.
|
2014-08-19 20:41:23 +08:00
|
|
|
|
2016-11-29 04:57:58 +08:00
|
|
|
You should not consider `RANDOM` cryptographically secure, or even
|
|
|
|
statistically accurate.
|
2005-09-20 21:31:55 +08:00
|
|
|
|
|
|
|
\subsection random-example Example
|
|
|
|
|
2016-11-29 04:57:58 +08:00
|
|
|
The following code will count down from a random even number between 10 and 20 to 1:
|
2016-12-25 05:52:49 +08:00
|
|
|
|
2014-08-01 10:37:32 +08:00
|
|
|
\fish
|
2016-11-29 04:57:58 +08:00
|
|
|
for i in (seq (random 10 2 20) -1 1)
|
2014-08-01 10:37:32 +08:00
|
|
|
echo $i
|
2005-09-20 21:31:55 +08:00
|
|
|
end
|
2014-08-01 10:37:32 +08:00
|
|
|
\endfish
|
2016-12-25 05:52:49 +08:00
|
|
|
|
2016-11-29 04:57:58 +08:00
|
|
|
And this will open a random picture from any of the subdirectories:
|
2016-12-25 05:52:49 +08:00
|
|
|
|
|
|
|
\fish
|
2016-11-29 04:57:58 +08:00
|
|
|
open (random choice **jpg)
|
|
|
|
\endfish
|