haskell / mwc-random

A very fast Haskell library for generating high quality pseudo-random numbers.
http://hackage.haskell.org/package/mwc-random
BSD 2-Clause "Simplified" License
54 stars 25 forks source link

Documentation or helper function on generating random bytestrings #55

Closed benma closed 4 years ago

benma commented 8 years ago

Thanks for this package!

Generating random bytestrings of length N is, I assume, a frequent enough operation to streamline this with either documentation (example code snippet), or even a helper function.

It took me too much time too research how to do that with this package. The right way seems to be to generate a vector and convert that somehow to a bytestring (maybe using https://hackage.haskell.org/package/spool?). Each of the steps (research, finding out how to convert, etc.) is detracting me from my real work. I was a bit surprised it is not supported natively by the package.

What do you think?

Shimuuar commented 8 years ago

Thank you for the report!

This is a simple task which require unordinate amount of legwork. So it should be at least documented. Or even helper functions uniformByteString :: (Gen (PrimState m) → m Word8) → Int → Gen (PrimState m) → m ByteString could be added.

benma commented 8 years ago

A helper function like that would incur a dependency on the bytestring package, right? Would that be a problem?

Shimuuar commented 8 years ago

I don't think so. bytestrings is used like everywhere so adding it as dependency shouldn't be a problem

benma commented 4 years ago

Amazing!