-
Notifications
You must be signed in to change notification settings - Fork 38
Add bytestream-based 'random' module with PRNG and /dev/urandom handlers & fix float ops on Chez #966
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
Conversation
def unixRandom(): Unit = { | ||
with boundary; | ||
with on[IOError].report; | ||
with devurandom; | ||
|
||
repeat(2) { | ||
println(randomInt32()) | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is not actually called for testing purposes (since how would we figure out if it works?), but serves as a quick demo.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If we'd want, we could add a test that just asserts that we get some values (not an error).
Note that on Mac/M1, this leads to segfaults for me on LLVM 🤔 (but probably that's the known problem)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM.
Generated randomness also seems to be OK (at least for my superfluous testing).
def unixRandom(): Unit = { | ||
with boundary; | ||
with on[IOError].report; | ||
with devurandom; | ||
|
||
repeat(2) { | ||
println(randomInt32()) | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If we'd want, we could add a test that just asserts that we get some values (not an error).
Note that on Mac/M1, this leads to segfaults for me on LLVM 🤔 (but probably that's the known problem)
…ers & fix float ops on Chez (effekt-lang#966) Straightforward streaming randomness with an interface supporting both bytes-based PRNG and /dev/urandom.
Straightforward streaming randomness based on bytes, see the
examples
namespace.The goal is to unblock #893.
The generator is specialised for 32-bit numbers, always returning only the lowest byte (which might be bad / inefficient, but oh well).
Here's more about the algorithm https://en.wikipedia.org/wiki/Lehmer_random_number_generator
Goals:
Int
through weird shifting behaviour...)Non-goals: