Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Random number generator - a class or a record? #19602

Open
vasslitvinov opened this issue Apr 5, 2022 · 4 comments
Open

Random number generator - a class or a record? #19602

vasslitvinov opened this issue Apr 5, 2022 · 4 comments

Comments

@vasslitvinov
Copy link
Member

Should the random generator provided by the standard library be:

  • a class (which it currently is), or
  • a record, or
  • a record-wrapped class?

Issues to consider:

  • What do we want to be the initialization/assignment semantics -- duplicating the reference or copying? Many of our standard data structures perform copying. For a random number generator copying means starting at the same place. Whatever approach we take, semantics of when copies are made should be obvious to user.

  • What is the desired behavior for remote accesses? For example, what should fillRandom() do? Currently it creates a per-locale version.

  • If it is a class, it is easy for nilability or ownership issues to start biting the user. Although nilability is unlikely to become an issue because the user variable holding the class will likely be non-nilable.

  • If it is a record-wrapped class, what should be the ownership policy? This perhaps comes back to the above question on copy semantics. Having just a record seems simpler conceptually, easier to use.

  • If it is a record-wrapped class, how much additional complexity does this introduce for the implementer of another generator?

@vasslitvinov
Copy link
Member Author

The first step is to make a prototype solution, once the Random module has been simplified to provide just a single type of random number generator. See also #19601

@bradcray
Copy link
Member

bradcray commented Apr 5, 2022

I think it should be a record from the user's perspective, and whether or not it wraps a class is our business as the implementers.

@mppf
Copy link
Member

mppf commented Apr 7, 2022

IMO it can and should be a plain record. The state is relatively small and can just be copied around. Also, it makes intuitive sense to me, if I copy an RNG, that I can advance each copy independently.

@lydia-duncan
Copy link
Member

Random is no longer intended for 2.0, removing the tag

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

No branches or pull requests

4 participants