ztk::game random
Gives a number of the random generator of the game, or sets its seed.
ztk::game random ?MIN MAX?
ztk::game random -seed N
Description
With no argument, gives a float from 0 to 1, less than 1. With two integers, gives an integer from MIN to MAX, both included, each with the same chance. With two other numbers, gives a float from MIN to MAX. -seed N starts the generator again from the integer N. The seed at the start is 0.
The generator is splitmix64, with integer operations only, so each platform gives the same numbers for a seed. Use it in place of rand(), so that a seed and the same input give the same game.
Returns
A number, or an empty string for -seed.
Examples
% ztk::game random -seed 1
> list [ztk::game random 1 6] [ztk::game random 1 6]
6 2
% ztk::game random -seed 0
> ztk::game random
0.8833108082136426
Errors
% ztk::game random 6 1
min 6 is above max 1
-errorcode ZTK GAME RANGE
% ztk::game random 1
wrong # args: should be "ztk::game random ?min max? | ztk::game random -seed n"
-errorcode TCL WRONGARGS
Facts
- Capability
- None.
- Tcl release
- Tcl 9.1 and 8.6.
- Since
- ztk 1.0.0-beta.7