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

hackett/data/random #47

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open

hackett/data/random #47

wants to merge 2 commits into from

Conversation

iitalics
Copy link
Contributor

I'd like to hear all possible feedback on this implementation before I add anything. I understand where @aaronmcdaid is coming from; it feels very awkward to convert to/from pseudo-random-number-generators, but I suppose it works and provides a pure interface.

@aaronmcdaid
Copy link

aaronmcdaid commented Oct 19, 2017

Love the rewrite, @iitalics . I've only just now managed to read it fully, learning more Racket on the way (parameters and parameterize).

There is an issue with random/io where it will usually give the same value repeatedly. This is because it recreates each time and Racket seeds it with a function of the current time (down to milliseconds). Usually, two consecutive draws are at the same time and therefore the same seed. When I run this code, I tend to get runs of four or five identical integers:

(main (do
        {random/io >>= {print . ((flip ++) "\n") . show . (+ 0)}}
        {random/io >>= {print . ((flip ++) "\n") . show . (+ 0)}}
        {random/io >>= {print . ((flip ++) "\n") . show . (+ 0)}}
        {random/io >>= {print . ((flip ++) "\n") . show . (+ 0)}}
        {random/io >>= {print . ((flip ++) "\n") . show . (+ 0)}}
        {random/io >>= {print . ((flip ++) "\n") . show . (+ 0)}}
        {random/io >>= {print . ((flip ++) "\n") . show . (+ 0)}}
        {random/io >>= {print . ((flip ++) "\n") . show . (+ 0)}}
        {random/io >>= {print . ((flip ++) "\n") . show . (+ 0)}}))

(Edited) Now I think I realise what you are doing with the RandomT code at the end that you have commented out. It's about chaining the computations together, and this would be relevant to starting with one called to make-io-prng and then feeding that into a stream of computations.)

@lexi-lambda
Copy link
Owner

I agree that it probably makes sense to provide an interface to create a fresh PRNG. It may also make sense to provide a random/io function, but make it use Racket’s global/default PRNG. There’s no need to have a pure, self-contained generator if you can only use it in IO, anyway, since it’s random, and other modifications to the generator state are not meaningfully observable.

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

Successfully merging this pull request may close these issues.

None yet

3 participants