H3lp Yours3lfDocs
api

randomGen

Generate fast, independent pseudo-random values without consuming OpenMW's protected random stream.

Used in the St4sh
  • CHIM 2090: roll/core.lua — Roll manager settings, attached actor access, and randomized roll audio.
  • S3maphore: music/core.lua — A production music loop combining actor state, transitions, cleanup, magic checks, and randomized selection.
  • H4ND: TTTH/hud.lua — A HUD consumer combining attached actor data, settings state, atlas frames, magic calculations, and randomized presentation.
  • Static Switching System: actionHandlers.lua, moduleCatalog.lua, staticReplacements.lua, global.lua — Action variation, spatial indexing, content fingerprints, and optional callbacks across the replacement pipeline.
require 'scripts.s3.randomGen' → Rand

Use randomGen when a mod needs randomness that should not consume or reseed OpenMW's engine-managed random stream. H3 keeps a private module-level xorshift state, seeded from real time when the module loads. This makes it a useful escape hatch for independent gameplay rolls, cosmetic variation, and randomized selection without asking OpenMW to hand over its protected seed.

Example

local random = require 'scripts.s3.randomGen'

local chance = random.float()
if chance <= 0.25 then playRareEffect() end

local index = random.range(1, #entries, true)
local pitch = random.range(-2, 2)

Values and ranges

FunctionBehavior
int()Advance the private xorshift stream and return its 32-bit integer value.
float()Return a floating-point value in [0, 1).
range(max)Return a continuous value in [1, max).
range(max, true)Return a uniform integer in [1, max].
range(min, max)Return a continuous value in [min, max).
range(min, max, true)Return a uniform integer spanning the requested endpoints.

The direct numeric overloads deliberately avoid an options table and its allocation. Pass true as the second argument for the one-bound integer form, or as the third argument for the two-bound form. Bounds are not validated; invalid types raise, while reversed or otherwise nonsensical numeric bounds produce whatever the arithmetic implies. The H3 implementation keeps the hot path small: direct arguments, cached math/bit operations, and no result table.

The H4ND legacy call site passes a table-shaped range argument, while the current H3 implementation accepts direct numeric arguments. Use the forms above when writing new code; that call site should be audited separately.