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

topic proposal: pseudorandom number generators #30

Open
rtfeldman opened this issue Mar 12, 2024 · 1 comment
Open

topic proposal: pseudorandom number generators #30

rtfeldman opened this issue Mar 12, 2024 · 1 comment
Assignees
Labels
assigned Topic has been assigned in-content Is the issue in lesson content?
Milestone

Comments

@rtfeldman
Copy link
Contributor

We already have an implementation of PCG pseudorandom number generation in roc-random but implementing random generators in a purely functional language seems like a good fit for this book because:

  • Most languages have something like a random() function which isn't pure (since it potentially returns a different answer each time it's called). Because of this, it's a common beginner surprise to discover that a random number generator in a pure FP language has to present a different API.
  • There are a bunch of different PRNG algorithms out there, including ones that are simple enough that you can write the "randomness" part in a few lines of code, and then focus on the concept of how computers do "randomness" and pure FP API differences (including generating things other than numbers) for the rest of the chapter - which are the more interesting parts.
  • There's a good opportunity for some "further reading" notes on why algorithms like PCG and xoroshiro provide better distributions of outputs, performance tradeoffs, entropy sources for secure randomness, etc.
@gvwilson gvwilson added help-wanted A request for assistance discuss An issue or PR currently being discussed in-content Is the issue in lesson content? propose-addition A suggestion for an addition to content or infrastructure labels Mar 12, 2024
@gvwilson gvwilson added this to the topic-outline milestone Mar 12, 2024
@gvwilson gvwilson changed the title topic proposal: Pseudorandom generators topic proposal: pseudorandom number generators Mar 13, 2024
@nathanielknight
Copy link
Contributor

nathanielknight commented Mar 20, 2024

(Copied from Zulip)

I think I'm interested in contributing to the chapter on PRNGs. I don't have a lot of Roc experience, but I'm comfortable with numerical programming and technical writing.

I think something in the PCG family of RNGs would be a good one to use; it's got good numerical properties and is very compact.

In terms of content, I'd see the following sections:

  • what's a PRNG and why can't a pure random function exist in Roc
  • implementing a naive PRNG (e.g. RANDU) that generates random 32-bit integers and has an opaque state
  • extending the PRNG to generate other kinds of integer, floats, maybe arrays (depending on how much type wizardry the reader is ready for / I'm ready to explain 😅 )
  • testing the statistical properties of the naive PRNG and finding it wanting
  • replacing our naive PRNG with a PCG which, thanks to our opaque state, doesn't affect the extensions we wrote 🎉

@gvwilson gvwilson added assigned Topic has been assigned and removed help-wanted A request for assistance discuss An issue or PR currently being discussed propose-addition A suggestion for an addition to content or infrastructure labels Apr 10, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
assigned Topic has been assigned in-content Is the issue in lesson content?
Projects
None yet
Development

No branches or pull requests

3 participants