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

Update the random number generation page to use rand 0.6 #497

Open
ivandardi opened this Issue Nov 14, 2018 · 1 comment

Comments

Projects
None yet
2 participants
@ivandardi

ivandardi commented Nov 14, 2018

The rand crate just released its 0.6 release, so the cookbook should be updated accordingly, especially since the API got a big more ergonomic to use.

Here's an update guide: https://rust-random.github.io/book/update-0.6.html

Here's an overview of how code with rand looks like: https://rust-random.github.io/book/overview.html

The biggest benefit is the random() function being able to generate values of any type with just importing the prelude, which is really useful. One note I'd like to say is that generating random booleans should be in the cookbook because that functionality is extremely common and most people use if rng.gen::<f64>() < 0.5 which works but doesn't look as good as the recent if random()

@dhardy

This comment has been minimized.

Contributor

dhardy commented Nov 14, 2018

Slight correction: random() isn't new; it's had roughly that functionality as long as I remember (perhaps not everyone realised).

We also have e.g. rng.gen_bool(0.2) if you want other probabilities.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment