Skip to content

rust-guide::13.3 Generating a secret number #15954

Closed
@anmej

Description

@anmej

cc @steveklabnik

This part is somewhat confusing:
let secret_number = (rand::random::<int>() % 100i) + 1i;

My suggestion is: either mention that rand::random::<int>() samples the whole range of int and you use modulo to narrow the range. Or use the std::rand::distributions::Range function. This way you also don't get modulo bias.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions