Skip to content

feat: implement random number generation #23

@mjm918

Description

@mjm918

Summary

Add random number generation to naml runtime for games, simulations, and general use.

Proposed API

// Generate random integer in range [min, max] inclusive
fn random(min: int, max: int) -> int;

// Generate random float in range [0.0, 1.0)
fn random_float() -> float;

Use Cases

  • Games (random food placement, enemy behavior)
  • Simulations
  • Shuffling, sampling
  • UUID generation

Implementation Notes

  • Use a fast PRNG (xorshift, PCG, or similar)
  • Seed from system entropy on startup
  • Platform considerations:
    • Native: rand crate or custom PRNG
    • Server WASM: WASI random_get
    • Browser: Math.random() or WebCrypto

Acceptance Criteria

  • random(min, max) returns integer in specified range
  • random_float() returns float in [0.0, 1.0)
  • Distribution is reasonably uniform
  • Works on native platform

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions