feat: add WELL512-based Random module with seed, float, and int methods
Implement a new `random` module for the Wren language runtime, providing a `Random` class backed by the WELL512a PRNG algorithm. The module supports three seeding strategies (time-based, single numeric seed, and 16-element sequence), generates uniform floats in [0,1) and integers in the full uint32 range, and includes convenience methods for bounded ranges. The implementation adds the C foreign functions `randomAllocate`, `randomSeed0`, `randomSeed1`, `randomSeed16`, `randomFloat`, and `randomInt0`, registers them in the module registry, and includes the Wren wrapper class with constructors accepting no arguments, a number, or a sequence. The commit also adds 12 test scripts covering float/int generation, seeding reproducibility, and error handling for invalid seed types.
This commit is contained in:
@@ -0,0 +1,18 @@
|
||||
import "random" for Random
|
||||
|
||||
var random = Random.new(12345)
|
||||
|
||||
var counts = [0, 0, 0, 0, 0, 0, 0, 0]
|
||||
for (i in 1..10000) {
|
||||
var n = random.int(3, 8)
|
||||
counts[n] = counts[n] + 1
|
||||
}
|
||||
|
||||
for (i in 0..2) {
|
||||
if (counts[i] != 0) System.print("too low value")
|
||||
}
|
||||
|
||||
for (i in 3..7) {
|
||||
if (counts[i] < 1900) System.print("too few")
|
||||
if (counts[i] > 2100) System.print("too many")
|
||||
}
|
||||
Reference in New Issue
Block a user