Skip to content

Enhance Random Effect with Additional Generators & Seeding #42

Description

@haskiindahouse

Summary

The current Random effect exposes only three basic methods:

Random.nextBoolean
Random.nextInt
Random.nextDouble

To support a broader range of use-cases—statistical simulations, property-based testing, cryptography utilities, etc.—we should expand the Random API with advanced generators and enable deterministic reproducibility via seeding.

Motivation

  • Richer functionality
    Advanced generators such as nextGaussian (normal distribution) and nextBytes ❓ unlock Monte Carlo algorithms, numeric simulations, realistic test data, and more.
  • Determinism & Reproducibility
    Seeding the RNG is critical for writing repeatable tests and debugging non-deterministic issues.

Proposed API Additions

import in.rcard.yaes.Random

trait Random:
  ...
  /** Gaussian (normal) distribution with mean 0.0 and std-dev 1.0 */
  def nextGaussian: Double

  /** Returns a new Random instance initialized with the specified seed */
  def withSeed(seed: Long): Random

Implementation Sketch

  • Leverage java.util.random.RandomGenerator (Java 17+) under the hood for all methods. (now using scala.random package)

Acceptance Criteria

  1. API surface
    • Implement nextGaussian.
    • Add withSeed(seed: Long) for deterministic instances.
  2. Correctness
    • Property-based tests confirming Gaussian mean ≈ 0.0.
    • Uniformity tests for nextInt(n) and nextBytes.
  3. Documentation
    • Update README with usage examples.
  4. Compatibility
    • Preserve binary compatibility for existing calls to nextInt, nextDouble, and nextBoolean.

References

  • Java 17 RandomGenerator API – rich RNG support with seeding.
  • ScalaCheck – examples of deterministic generators in property-based tests.
  • Cats Effect (cats.effect.std.Random) – inspiration for method signatures and semantics.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions