-
Notifications
You must be signed in to change notification settings - Fork 510
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
Add function for generating random values #2049
Conversation
README.md
Outdated
- `pick(len)`<sup>master</sup> - Generate a string of `len` random lowercase hexadecimal digit characters. | ||
- `pick(len, alphabet)`<sup>master</sup> - Generate a random string of length `len` consisting of characters found in `alphabet`. |
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 you're into it, you could add some examples of the use to the examples
folder -- maybe under the existing kitchen sink ones?
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.
I think it's fine not to. I don't really require adding examples for every new function. An example can be added to the readme though.
Hey @laniakea64 thanks for the quick turnaround on this! One more thing that would be awesome are some tests! There's not much you can test (especially as this is real random and not pseudo random), but at the very least the string formation/length might be worth testing! I wonder if you can easily test entropy (I assume GH runners have enough and this won't be a problem) |
You're welcome, thanks for your review!
Done.
I have no idea how to even start there, sorry 😨 |
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.
Looks good! I think we should this function choose
. I was poking around, and that seems to be the most common name.
README.md
Outdated
- `pick(len)`<sup>master</sup> - Generate a string of `len` random lowercase hexadecimal digit characters. | ||
- `pick(len, alphabet)`<sup>master</sup> - Generate a random string of length `len` consisting of characters found in `alphabet`. |
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.
I think it's fine not to. I don't really require adding examples for every new function. An example can be added to the readme though.
LGTM! I just merged #2054, which adds some predefined constants, including I actually think that, in the general case, pre-allocating the string length isn't useful. The length of a string is in bytes, but characters may be multiple bytes when encoded in UTF-8. |
Adds
pick()
function as discussed in #1991 (comment)I'm still relatively new to Rust, so code review would be much appreciated 🙂
cc @t3hmrman