Skip to content

Commit

Permalink
predictable patterns
Browse files Browse the repository at this point in the history
  • Loading branch information
dilawar committed Sep 18, 2024
1 parent f53c8ed commit 9621c81
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 6 deletions.
3 changes: 2 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
[package]
name = "cron-within-interval"
name = "cron-with-randomness"
version = "0.1.0"
edition = "2021"

Expand All @@ -9,6 +9,7 @@ chrono = "0.4"
cron = "0.12"
lazy_static = "1.5"
rand = "0.8"
rand_chacha = "0.3.1"
regex = "1.10"

[dev-dependencies]
Expand Down
7 changes: 4 additions & 3 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,8 @@ use std::collections::HashMap;
use std::str::FromStr;

use cron::Schedule;
use rand::{seq::SliceRandom, Rng};
use rand::prelude::*;
use rand_chacha::ChaCha8Rng;
use regex::Regex;

/// Global seed fro rngs.
Expand Down Expand Up @@ -112,7 +113,7 @@ impl CronWithRandomness {
where
Z: chrono::TimeZone,
{
let mut rng = rand::StdRng::seed_from_u64(SEED);
let mut rng = ChaCha8Rng::seed_from_u64(SEED);
let mut result_datetime = datetime.clone();

// pick a random minute. We have to reduce one hour from the hour range after this.
Expand Down Expand Up @@ -160,7 +161,7 @@ impl FromStr for Interval {
impl Interval {
/// Generate a random value between the interval
fn random(&self) -> i16 {
let mut rng = rand::StdRng::seed_from_u64(SEED);
let mut rng = ChaCha8Rng::seed_from_u64(SEED);
// high is exclusive
rng.gen_range(self.0..self.1)
}
Expand Down
3 changes: 1 addition & 2 deletions src/main.rs
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
//! Binary to generate patterns.
use std::str::FromStr;

use chrono::Utc;
use cron_with_randomness::CronWithRandomness;
use std::str::FromStr;

fn main() {
let pattern = std::env::args().nth(1).expect("no pattern given");
Expand Down

0 comments on commit 9621c81

Please sign in to comment.