hackett icon indicating copy to clipboard operation
hackett copied to clipboard

hackett/data/random

Open iitalics opened this issue 8 years ago • 2 comments

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.

iitalics avatar Oct 18 '17 04:10 iitalics

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.)

aaronmcdaid avatar Oct 19 '17 22:10 aaronmcdaid

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.

lexi-lambda avatar Oct 20 '17 03:10 lexi-lambda