From 5934b163f5237f266a6fd2db7e6d3af237d9c1a2 Mon Sep 17 00:00:00 2001 From: Palash Tyagi <23239946+Magnus167@users.noreply.github.com> Date: Mon, 28 Jul 2025 20:37:08 +0100 Subject: [PATCH] Refactor random number generation to use rustframe's random module --- examples/game_of_life.rs | 6 +++--- src/compute/models/dense_nn.rs | 4 ++-- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/examples/game_of_life.rs b/examples/game_of_life.rs index 020a0a5..e596cda 100644 --- a/examples/game_of_life.rs +++ b/examples/game_of_life.rs @@ -5,8 +5,8 @@ //! To modify the behaviour of the example, please change the constants at the top of this file. //! By default, -use rand::{self, Rng}; use rustframe::matrix::{BoolMatrix, BoolOps, IntMatrix, Matrix}; +use rustframe::random::{rng, Rng}; use std::{thread, time}; const BOARD_SIZE: usize = 20; // Size of the board (50x50) @@ -265,7 +265,7 @@ pub fn generate_glider(board: &mut BoolMatrix, board_size: usize) { // Initialize with a Glider pattern. // It demonstrates how to set specific cells in the matrix. // This demonstrates `IndexMut` for `current_board[(r, c)] = true;`. - let mut rng = rand::rng(); + let mut rng = rng(); let r_offset = rng.random_range(0..(board_size - 3)); let c_offset = rng.random_range(0..(board_size - 3)); if board.rows() >= r_offset + 3 && board.cols() >= c_offset + 3 { @@ -281,7 +281,7 @@ pub fn generate_pulsar(board: &mut BoolMatrix, board_size: usize) { // Initialize with a Pulsar pattern. // This demonstrates how to set specific cells in the matrix. // This demonstrates `IndexMut` for `current_board[(r, c)] = true;`. - let mut rng = rand::rng(); + let mut rng = rng(); let r_offset = rng.random_range(0..(board_size - 17)); let c_offset = rng.random_range(0..(board_size - 17)); if board.rows() >= r_offset + 17 && board.cols() >= c_offset + 17 { diff --git a/src/compute/models/dense_nn.rs b/src/compute/models/dense_nn.rs index cdb2e32..ab5c05c 100644 --- a/src/compute/models/dense_nn.rs +++ b/src/compute/models/dense_nn.rs @@ -1,6 +1,6 @@ use crate::compute::models::activations::{drelu, relu, sigmoid}; use crate::matrix::{Matrix, SeriesOps}; -use rand::prelude::*; +use crate::random::prelude::*; /// Supported activation functions #[derive(Clone)] @@ -46,7 +46,7 @@ pub enum InitializerKind { impl InitializerKind { pub fn initialize(&self, rows: usize, cols: usize) -> Matrix { - let mut rng = rand::rng(); + let mut rng = rng(); let fan_in = rows; let fan_out = cols; let limit = match self {