-
Notifications
You must be signed in to change notification settings - Fork 13.6k
Closed
Description
It might be worth mentioning that generating a uint
directly is more efficient than generating an int
and calling abs
(unless the compiler is very clever).
When reading the code I was wondering why
let secret_number = (rand::random() % 100u) + 1;
would not compile. Shouldn't the compiler be able to infer the correct specialization of random
?
Also, it might be more idiomatic to write
let secret_number = (rand::random::<uint>() % 100) + 1;
than using redundant integer literals
let secret_number = (rand::random::<uint>() % 100u) + 1u;
Metadata
Metadata
Assignees
Labels
No labels