Skip to content

Implement random number generator and sampling in mohu-random #140

Description

@Bbn08

Summary

mohu-random is a stub crate. Implement a seeded RNG and the three most commonly needed distributions for numerical computing.

API surface

pub struct Rng { /* seeded state */ }

impl Rng {
    pub fn new(seed: u64) -> Self;
    pub fn uniform(shape: &[usize], low: f64, high: f64) -> MohuResult<Buffer>;
    pub fn normal(shape: &[usize], mean: f64, std: f64)  -> MohuResult<Buffer>;
    pub fn integers(shape: &[usize], low: i64, high: i64) -> MohuResult<Buffer>;
}

Implementation guide

  • Use rand crate (already in workspace or add it)
  • Seed reproducibility: same seed must yield same output across runs
  • uniform: output dtype F64; high <= low returns DomainError
  • normal: use Box-Muller or Ziggurat; std <= 0 returns DomainError
  • integers: output dtype I64; high <= low returns DomainError

Acceptance criteria

  • Same seed produces identical output (reproducibility test)
  • uniform values in [low, high) range
  • normal mean and std within tolerance for large N (e.g., N=100000)
  • integers values in [low, high) range
  • DomainError for invalid range arguments
  • No .unwrap() in library code

Signed-off-by: Bbn08 atrancendentbeing@gmail.com

Metadata

Metadata

Labels

GSSoCReserved for GSSoC contributorsenhancementNew feature or request

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions