Skip to content

thread_rng().gen_range() deprecated in `rand = "0.9.2" for auth_service #21

@kevinkurek

Description

@kevinkurek

Not a huge deal but making it apparent for anyone else who get this issue.
Path: bootcamp/1. Beginner/4. How To Structure Your Rust Projects/auth_service/

Issue:


# Cargol.toml
rand = "0.8.4" # newest version is now 0.9.2 so use rand::prelude::* is deprecated.

# lib.rs
#![allow(dead_code, unused_variables)]
use rand::prelude::*;

pub mod database;
mod auth_utils;

pub use auth_utils::models::Credentials;
use database::Status;

pub fn authenticate(creds: Credentials) {
    let timeout = 
        thread_rng().gen_range(100..500);
    println!("The timeout is {timeout}");
    if let Status::Connected = database::connect_to_database() {
        auth_utils::login(creds);
    }
}



Solution:

# Cargo.toml
rand = "0.9.2"

# lib.rs
#![allow(dead_code, unused_variables)]
use rand::Rng;

pub mod database;
mod auth_utils;

pub use auth_utils::models::Credentials;
use database::Status;

pub fn authenticate(creds: Credentials) {
    let timeout = rand::rng().random_range(100..=500);
    println!("The timeout is {timeout}");

    if let Status::Connected = database::connect_to_database() {
        auth_utils::login(creds);
    }
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions