Skip to content

Petrichor.Random#

require("Petrichor.Random") provides deterministic PRNG helpers for mods and generators.

Module-level xorshift32#

Global xorshift32 state. Handy when you want one shared sequence for a short script.

local Random = require("Petrichor.Random")

Random.seed(0x6C8E9CF5)
local n = Random.next()
local f = Random.nextFloat()
import * as Random from "Petrichor.Random"

Random.seed(0x6C8E9CF5)
const n = Random.next()
const f = Random.nextFloat()

Random.xorshift (instance)#

local rng = require("Petrichor.Random").xorshift.new(12345)
local n = rng:next()
local f = rng:nextFloat()
import * as Random from "Petrichor.Random"

const rng = Random.xorshift.new(12345)
const n = rng.next()
const f = rng.nextFloat()

Random.system#

A System.Random-style LCG. Use it when you need the same integer sequence as other tools that implement that algorithm.

local SystemRandom = require("Petrichor.Random").system
local rnd = SystemRandom.new(0xDEADBEEF)
local index = rnd:next(10) -- 0 .. 9
import * as Random from "Petrichor.Random"

const rnd = Random.system.new(0xDEADBEEF)
const index = rnd.next(10) // 0 .. 9