add random generation in simulator IO

This commit is contained in:
pedrocarlo
2025-10-21 11:44:40 -03:00
parent 8c0b9c6979
commit 72baf48863
3 changed files with 17 additions and 4 deletions

View File

@@ -3,7 +3,7 @@ use std::{
sync::Arc,
};
use rand::{RngCore, SeedableRng};
use rand::{Rng, RngCore, SeedableRng};
use rand_chacha::ChaCha8Rng;
use turso_core::{Clock, IO, Instant, OpenFlags, PlatformIO, Result};
@@ -136,6 +136,10 @@ impl IO for SimulatorIO {
}
fn generate_random_number(&self) -> i64 {
self.rng.borrow_mut().next_u64() as i64
self.rng.borrow_mut().random()
}
fn fill_bytes(&self, dest: &mut [u8]) {
self.rng.borrow_mut().fill_bytes(dest);
}
}

View File

@@ -3,7 +3,7 @@ use std::sync::Arc;
use indexmap::IndexMap;
use parking_lot::Mutex;
use rand::{RngCore, SeedableRng};
use rand::{Rng, RngCore, SeedableRng};
use rand_chacha::ChaCha8Rng;
use turso_core::{Clock, Completion, IO, Instant, OpenFlags, Result};
@@ -269,7 +269,11 @@ impl IO for MemorySimIO {
}
fn generate_random_number(&self) -> i64 {
self.rng.borrow_mut().next_u64() as i64
self.rng.borrow_mut().random()
}
fn fill_bytes(&self, dest: &mut [u8]) {
self.rng.borrow_mut().fill_bytes(dest);
}
fn remove_file(&self, path: &str) -> Result<()> {

View File

@@ -142,6 +142,11 @@ impl IO for SimulatorIO {
let mut rng = self.rng.lock().unwrap();
rng.next_u64() as i64
}
fn fill_bytes(&self, dest: &mut [u8]) {
let mut rng = self.rng.lock().unwrap();
rng.fill_bytes(dest);
}
}
const MAX_FILE_SIZE: usize = 1 << 33; // 8 GiB