API Reference › Crypto › Crypto.random_u32
method

Crypto.random_u32

Crypto.random_u32() -> int

Draws four bytes from the OS CSPRNG and assembles them into one 32-bit integer. Use it when you need a single unpredictable number rather than a hex string — a random challenge value, a per-run identifier, or a non-deterministic seed to hand to a *fresh* Random stream at startup. Because the bytes come from the secure generator, the value prints as a signed integer and can be negative.

Like the other secure-random helpers this is **non-deterministic** and must not be called inside the lockstep simulation: doing so desyncs replays and networked peers. Draw it at the edges (startup, on connect) and, if you need reproducible gameplay randomness afterward, seed Random.seed with it once.

Example

program Challenge {
  entry {
    let c = Crypto.random_u32()
    Random.seed(value: c)          # non-deterministic seed, chosen once at startup
    print(Random.int(100))
  }
}
← All symbols