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

math/rand: add io.Reader interface to type Rand #8330

Closed
wathiede opened this issue Jul 4, 2014 · 8 comments
Closed

math/rand: add io.Reader interface to type Rand #8330

wathiede opened this issue Jul 4, 2014 · 8 comments

Comments

@wathiede
Copy link
Member

wathiede commented Jul 4, 2014

This is a feature request I would be willing to implement if it is deemed appropriate.

I often find myself wanting to generate large pseudo-randomly filled files for testing
and benchmarks.  The io.Reader interface in crypto/rand is nice, but it is
non-deterministic by design.  Having an io.Reader interface on math/rand.Rand, paired
with a consistent seed, would allow consistent random number generation from run-to-run
of tests and benchmarks.

Would this be an appropriate addition to the standard library?
@ianlancetaylor
Copy link
Contributor

Comment 1:

Labels changed: added repo-main, release-none.

@bradfitz bradfitz removed the new label Dec 18, 2014
@jpillora
Copy link

👍 (Is +1ing issues the right way to show interest?)

@adg
Copy link
Contributor

adg commented Mar 18, 2015

@jpillora unfortunately @github provides no way to show support for an interest besides commenting, but that just creates comment spam. Better to provide more information about your particular use case explaining what might make this a compelling feature.

@jpillora
Copy link

@adg Will do that in the future. Basically, a deterministic crypto.Reader for reproducibility. In the mean time, I guess I could achieve this by repeatedly hashing some seed data and return the output stream.

@rsc rsc added this to the Unplanned milestone Apr 10, 2015
@spenczar
Copy link
Contributor

This issue is old and low priority, but simple to implement. I'd like to try contributing to Go - is there sufficient interest for me to submit a CR? I don't know whether APIs like math/rand.Rand are considered frozen.

@ianlancetaylor
Copy link
Contributor

I think it would be fine to add something to math/rand that implements io.Reader. Probably Rand should get a Read method. I'm not sure how to best implement it--pull seven bytes out of every call to Int63?

@spenczar
Copy link
Contributor

Yep, that's the plan.

I'll send a CR, thanks for the speedy reply!

@gopherbot
Copy link

CL https://golang.org/cl/14522 mentions this issue.

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

No branches or pull requests

8 participants