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
- API surface
- Implement
nextGaussian.
- Add
withSeed(seed: Long) for deterministic instances.
- Correctness
- Property-based tests confirming Gaussian mean ≈ 0.0.
- Uniformity tests for
nextInt(n) and nextBytes.
- Documentation
- Update README with usage examples.
- 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.
Summary
The current
Randomeffect exposes only three basic methods:To support a broader range of use-cases—statistical simulations, property-based testing, cryptography utilities, etc.—we should expand the
RandomAPI with advanced generators and enable deterministic reproducibility via seeding.Motivation
Advanced generators such as
nextGaussian(normal distribution) andnextBytes❓ unlock Monte Carlo algorithms, numeric simulations, realistic test data, and more.Seeding the RNG is critical for writing repeatable tests and debugging non-deterministic issues.
Proposed API Additions
Implementation Sketch
java.util.random.RandomGenerator(Java 17+) under the hood for all methods. (now using scala.random package)Acceptance Criteria
nextGaussian.withSeed(seed: Long)for deterministic instances.nextInt(n)andnextBytes.nextInt,nextDouble, andnextBoolean.References
cats.effect.std.Random) – inspiration for method signatures and semantics.