Skip to content

examples/print-next.rs#1647

Merged
dhardy merged 1 commit intomasterfrom
push-twkrrppsqxqz
Jul 20, 2025
Merged

examples/print-next.rs#1647
dhardy merged 1 commit intomasterfrom
push-twkrrppsqxqz

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