Skip to content

examples/print-next.rs #1647

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

Merged
merged 1 commit into from
Jul 20, 2025
Merged

examples/print-next.rs #1647

merged 1 commit into from
Jul 20, 2025

Conversation

dhardy
Copy link
Member

@dhardy dhardy commented Jul 16, 2025

Sometimes you just want a random number. It seems strange that we didn't already have a handy example to print this:

Next u32:           1035878085 = 0x3DBE3EC5
Next u64:  9250892210303435489 = 0x8061C573B29082E1

Also a fix for the new mismatched_lifetime_syntaxes lint.

@dhardy dhardy requested a review from newpavlov July 16, 2025 13:10
@dhardy
Copy link
Member Author

dhardy commented Jul 16, 2025

I'll rebase after #1646.

@dhardy dhardy force-pushed the push-twkrrppsqxqz branch from 520ceb6 to dc74661 Compare July 17, 2025 12:23
use rand::{rngs::OsRng, RngCore, TryRngCore};

fn main() {
let mut rng = TryRngCore::unwrap_err(OsRng);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ThreadRng could be better fit here.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We only make two calls to the OS for less total bytes than needed to seed ThreadRng.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is an example for unsophisticated users and we should direct them towards ThreadRng, not OsRng.

@dhardy dhardy force-pushed the push-twkrrppsqxqz branch from dc74661 to cd47b5f Compare July 20, 2025 12:28
@dhardy dhardy merged commit 031a1f5 into master Jul 20, 2025
13 checks passed
@dhardy dhardy deleted the push-twkrrppsqxqz branch July 20, 2025 12:35
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants