implement random workload generator
This commit is contained in:
21
ubw-sward/src/udp/generator.rs
Normal file
21
ubw-sward/src/udp/generator.rs
Normal file
@@ -0,0 +1,21 @@
|
||||
use rand::RngCore;
|
||||
|
||||
pub struct RandomUdpWorkloadGenerator<Rng: RngCore> {
|
||||
rng: Rng,
|
||||
}
|
||||
|
||||
impl<Rng: RngCore> RandomUdpWorkloadGenerator<Rng> {
|
||||
pub fn new(rng: Rng) -> Self {
|
||||
Self { rng }
|
||||
}
|
||||
pub fn generate_sized<const SIZE: usize>(&mut self) -> [u8; SIZE] {
|
||||
let mut buf = [0u8; SIZE];
|
||||
self.rng.fill_bytes(&mut buf);
|
||||
buf
|
||||
}
|
||||
pub fn generate_boxed(&mut self, size: usize) -> Box<[u8]> {
|
||||
let mut buf = vec![0u8; size].into_boxed_slice();
|
||||
self.rng.fill_bytes(&mut buf);
|
||||
buf
|
||||
}
|
||||
}
|
||||
@@ -1 +1,2 @@
|
||||
pub mod random_flood;
|
||||
pub mod random_flood;
|
||||
pub mod generator;
|
||||
Reference in New Issue
Block a user