Lynxer

Documentation

random

Seeded pseudo-random number and character helpers.

Backend: native — stdlib/random.so, built from stdlib/random.cpp. The generator is a linear congruential sequence, so a given seed always produces the same sequence (there is no process-global random state). Import: import("random") → global.random.*

FunctionSignatureNotes
seed(int value)Reseeds the generator; 0 restores the default seed
randint(int low, int high) -> intUniform integer in [low, high]; returns low when high <= low
randrange(int start, int stop) -> intUniform integer in [start, stop)
random() -> floatFloat in [0.0, 1.0)
uniform(float low, float high) -> floatFloat in [low, high]
coinflip() -> boolEqual-probability boolean
randBool() -> boolAlias of coinflip
choice(str items) -> strPicks one character of the input, or "" when empty

This is a subset of the original 17 functions; sampleInt, sampleStr, shuffle, triangular, gauss, uuid4 and randHex are not ported.

Example

global setup(){ import("random"); }

global main(){
    global.random.seed(7);
    println(global.random.randint(1, 6));   // 4
    println(global.random.choice("abc"));   // b
    println(global.random.uniform(0.0, 1.0));
}

See also