1
0
Fork 0
mirror of https://github.com/luanti-org/luanti.git synced 2025-08-16 18:01:40 +00:00

Add support for the PCG32 PRNG algo (and associated script APIs)

This commit is contained in:
kwolekr 2015-03-22 00:01:46 -04:00
parent 7679396ebb
commit 3993093f51
10 changed files with 415 additions and 179 deletions

View file

@ -2515,7 +2515,8 @@ an itemstring, a table or `nil`.
Returns taken `ItemStack`.
### `PseudoRandom`
A pseudorandom number generator.
A 16-bit pseudorandom number generator.
Uses a well-known LCG algorithm introduced by K&R.
It can be created via `PseudoRandom(seed)`.
@ -2525,6 +2526,19 @@ It can be created via `PseudoRandom(seed)`.
* `((max - min) == 32767) or ((max-min) <= 6553))` must be true
due to the simple implementation making bad distribution otherwise.
### `PcgRandom`
A 32-bit pseudorandom number generator.
Uses PCG32, an algorithm of the permuted congruential generator family, offering very strong randomness.
It can be created via `PcgRandom(seed)` or `PcgRandom(seed, sequence)`.
#### Methods
* `next()`: return next integer random number [`-2147483648`...`2147483647`]
* `next(min, max)`: return next integer random number [`min`...`max`]
* `rand_normal_dist(min, max, num_trials=6)`: return normally distributed random number [`min`...`max`]
* This is only a rough approximation of a normal distribution with mean=(max-min)/2 and variance=1
* Increasing num_trials improves accuracy of the approximation
### `PerlinNoise`
A perlin noise generator.
It can be created via `PerlinNoise(seed, octaves, persistence, scale)`