mirror of
https://github.com/MihailRis/voxelcore.git
synced 2026-10-09 13:01:49 +00:00
add 'random' library docs
This commit is contained in:
parent
532c4887bc
commit
eeddf894b3
4 changed files with 78 additions and 0 deletions
38
doc/en/scripting/builtins/librandom.md
Normal file
38
doc/en/scripting/builtins/librandom.md
Normal file
|
|
@ -0,0 +1,38 @@
|
|||
# *random* library
|
||||
|
||||
A library of functions for generating random numbers.
|
||||
|
||||
## Non-deterministic numbers
|
||||
|
||||
```lua
|
||||
-- Generates a random number in the range [0..1)
|
||||
random.random() --> number
|
||||
|
||||
-- Generates a random integer in the range [0..n]
|
||||
random.random(n) --> number
|
||||
|
||||
-- Generates a random integer in the range [a..b]
|
||||
random.random(a, b) --> number
|
||||
|
||||
-- Generates a random byte array of length n
|
||||
random.bytes(n: number) -> Bytearray
|
||||
|
||||
-- Generates a UUID version 4
|
||||
random.uuid() -> str
|
||||
```
|
||||
|
||||
## Pseudorandom numbers
|
||||
|
||||
The library provides the Random class - a generator with its own isolated state.
|
||||
|
||||
```lua
|
||||
local rng = random.Random()
|
||||
|
||||
-- Used similarly to math.random
|
||||
local a = rng:random() --> [0..1)
|
||||
local b = rng:random(10) --> [0..10]
|
||||
local c = rng:random(5, 20) --> [5..20]
|
||||
|
||||
-- Sets the generator state to generate a reproducible sequence of random numbers
|
||||
rng:seed(42)
|
||||
```
|
||||
Loading…
Add table
Add a link
Reference in a new issue