Skip to content

Future of splittable PRNG and infinite structures support #188

@jmcarthur

Description

@jmcarthur

The direction of the random package in recent releases emphasizes using StatefulGen instances with strict monads. This has led to several API changes:

  • Deprecation of RandomGenM
  • Deprecation of the split function in RandomGen
  • Introduction of the SplitGen class, which cannot be utilized in Random instances (with Random itself being discouraged)
  • Recommendation to use Uniform and UniformRange, which are restricted to finite value generation and do not leverage splittable PRNGs

I understand that most PRNGs are not splittable, and it is sensible to optimize the API around this common scenario. The current direction makes considerable sense for these typical use cases. However, I am concerned about the diminished support for use cases involving splittable PRNGs.

My specific context: I'm developing a package that needs to generate infinite data structures lazily. Previously, this could have been neatly handled via type class instances. With the current changes, generating infinite structures requires standalone functions. Additionally, my package employs a QuickCheck-style monad for lazy generation. While it's not impossible to implement with StatefulGen, the FrozenGen abstraction feels significantly less elegant than the deprecated RandomGenM in this scenario.

My impression is that these design choices were made with full awareness of the trade-offs involved. However, I haven't found issues or design documents explicitly addressing these decisions. I'm opening this issue primarily for clarity: if the current direction is fully intentional, documenting the rationale here will help others who encounter similar questions. Alternatively, if there is a broader plan to support lazy and infinite random value generation alongside monadic contexts, having that plan documented would be beneficial.

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