Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 5 additions & 5 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -25,20 +25,20 @@ wasm-bindgen = ["wasm-bindgen_", "chrono/wasmbind"]

[dependencies]
chrono = "0.4"
rand = { version = "0.8", default-features = false, features = ["getrandom"] }
rand_xoshiro = "0.6"
fixedbitset = { version = "0.4", optional = true }
rand = { version = "0.9", default-features = false, features = ["std", "os_rng"]}
rand_xoshiro = "0.7"
fixedbitset = { version = "0.5", optional = true }
smallvec = { version = "1", optional = true }

[target.'cfg(not(target_arch = "wasm32"))'.dependencies]
rayon = "1"

[target.'cfg(all(target_arch = "wasm32", not(any(target_os = "emscripten", target_os = "wasi"))))'.dependencies]
wasm-bindgen_ = { version = "0.2", package = "wasm-bindgen", optional = true }
getrandom = { version = "0.2", features = ["js", "wasm-bindgen"] }
getrandom = { version = "0.3", features = ["std"] }

[dev-dependencies]
criterion = "0.3"
criterion = "0.5"
galvanic-assert = "0.8"
proptest = "1"
version-sync = "0.9"
Expand Down
6 changes: 3 additions & 3 deletions benches/genome_builder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ extern crate criterion;
use criterion::{BenchmarkId, Criterion};
use genevo::random::{get_rng, random_seed};
use rand::{
distributions::{Bernoulli, Distribution},
distr::{Bernoulli, Distribution},
Rng,
};

Expand All @@ -15,7 +15,7 @@ fn generate_vec_of_random_bool_the_functional_way(c: &mut Criterion) {
for length in [12, 24, 48, 96] {
group.bench_with_input(BenchmarkId::from_parameter(length), &length, |b, length| {
b.iter(|| {
let _genome: Vec<bool> = (0..*length).map(|_| rng.gen()).collect();
let _genome: Vec<bool> = (0..*length).map(|_| rng.random()).collect();
})
});
}
Expand All @@ -31,7 +31,7 @@ fn generate_vec_of_random_bool_using_for_loop(c: &mut Criterion) {
let length = *length;
let mut genome: Vec<bool> = Vec::with_capacity(length);
for _ in 0..length {
genome.push(rng.gen());
genome.push(rng.random());
}
})
});
Expand Down
4 changes: 2 additions & 2 deletions examples/queens/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ impl RandomValueMutation for Pos {
{
Pos {
x: value.x,
y: rng.gen_range(min_value.y..max_value.y),
y: rng.random_range(min_value.y..max_value.y),
}
}
}
Expand All @@ -117,7 +117,7 @@ impl GenomeBuilder<Positions> for QueensPositions {
(0..NUM_ROWS)
.map(|row| Pos {
x: row,
y: rng.gen_range(0..NUM_COLS),
y: rng.random_range(0..NUM_COLS),
})
.collect()
}
Expand Down
4 changes: 2 additions & 2 deletions src/mutation/order.rs
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ where
{
let genome_length = genome.len();
let num_mutations =
((genome_length as f64 * self.mutation_rate) + rng.gen::<f64>()).floor() as usize;
((genome_length as f64 * self.mutation_rate) + rng.random::<f64>()).floor() as usize;
let mut mutated = genome;
for _ in 0..num_mutations {
let (locus1, locus2) = random_cut_points(rng, genome_length);
Expand Down Expand Up @@ -90,7 +90,7 @@ where
{
let genome_length = genome.len();
let num_mutations =
((genome_length as f64 * self.mutation_rate) + rng.gen::<f64>()).floor() as usize;
((genome_length as f64 * self.mutation_rate) + rng.random::<f64>()).floor() as usize;
let mut mutated = genome;
for _ in 0..num_mutations {
let (locus1, locus2) = random_cut_points(rng, genome_length);
Expand Down
20 changes: 10 additions & 10 deletions src/mutation/value.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ use crate::{
operator::{GeneticOperator, MutationOp},
random::{random_index, Rng},
};
use rand::seq::SliceRandom;
use rand::seq::IndexedRandom;
use std::fmt::Debug;

#[derive(Clone, Debug, PartialEq)]
Expand Down Expand Up @@ -92,7 +92,7 @@ where
{
let genome_length = genome.len();
let num_mutations =
((genome_length as f64 * mutation_rate) + rng.gen::<f64>()).floor() as usize;
((genome_length as f64 * mutation_rate) + rng.random::<f64>()).floor() as usize;
let mut mutated = genome;
for _ in 0..num_mutations {
let index = random_index(rng, genome_length);
Expand Down Expand Up @@ -129,11 +129,11 @@ mod fixedbitset_random_genome_mutation {
{
let genome_length = genome.len();
let num_mutations =
((genome_length as f64 * mutation_rate) + rng.gen::<f64>()).floor() as usize;
((genome_length as f64 * mutation_rate) + rng.random::<f64>()).floor() as usize;
let mut mutated = genome;
for _ in 0..num_mutations {
let bit = random_index(rng, genome_length);
let value = rng.gen();
let value = rng.random();
mutated.set(bit, value);
}
mutated
Expand Down Expand Up @@ -167,7 +167,7 @@ mod smallvec_random_genome_mutation {
{
let genome_length = genome.len();
let num_mutations =
((genome_length as f64 * mutation_rate) + rng.gen::<f64>()).floor() as usize;
((genome_length as f64 * mutation_rate) + rng.random::<f64>()).floor() as usize;
let mut mutated = genome;
for _ in 0..num_mutations {
let index = random_index(rng, genome_length);
Expand Down Expand Up @@ -197,22 +197,22 @@ macro_rules! impl_random_value_mutation {
fn random_mutated<R>(_: $t, min_value: &$t, max_value: &$t, rng: &mut R) -> $t
where R: Rng + Sized
{
rng.gen_range(*min_value..*max_value)
rng.random_range(*min_value..*max_value)
}
}
)*
}
}

impl_random_value_mutation!(u8, u16, u32, u64, usize, i8, i16, i32, i64, isize, f32, f64);
impl_random_value_mutation!(u8, u16, u32, u64, usize, i8, i16, i32, i64, f32, f64);

impl RandomValueMutation for bool {
#[inline]
fn random_mutated<R>(_value: bool, _min_value: &bool, _max_value: &bool, rng: &mut R) -> bool
where
R: Rng + Sized,
{
rng.gen_bool(0.5)
rng.random_bool(0.5)
}
}

Expand Down Expand Up @@ -321,7 +321,7 @@ where
{
let genome_length = genome.len();
let num_mutations =
((genome_length as f64 * mutation_rate) + rng.gen::<f64>()).floor() as usize;
((genome_length as f64 * mutation_rate) + rng.random::<f64>()).floor() as usize;
let mut mutated = genome;
for _ in 0..num_mutations {
let index = random_index(rng, genome_length);
Expand Down Expand Up @@ -368,4 +368,4 @@ macro_rules! impl_breeder_mutation {
}
}

impl_breeder_mutation!(u8, u16, u32, u64, usize, i8, i16, i32, i64, isize, f32, f64);
impl_breeder_mutation!(u8, u16, u32, u64, usize, i8, i16, i32, i64, f32, f64);
6 changes: 3 additions & 3 deletions src/operator/prelude.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
pub use crate::selection::{proportionate::*, ranking::*, tournament::*, truncation::*, *};
pub use crate::selection::{proportionate::*, tournament::*, truncation::*, *};

pub use crate::recombination::{discrete::*, order::*, *};
pub use crate::recombination::{discrete::*, *};

pub use crate::mutation::{order::*, value::*, *};
pub use crate::mutation::value::*;

pub use crate::reinsertion::{elitist::*, random::*, *};
6 changes: 3 additions & 3 deletions src/population/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ use crate::{
genetic::Genotype,
random::{get_rng, random_seed, Prng, Rng, Seed},
};
use rand::distributions::uniform::SampleUniform;
use rand::distr::uniform::SampleUniform;
#[cfg(not(target_arch = "wasm32"))]
use rayon;
use std::{fmt::Debug, marker::PhantomData};
Expand Down Expand Up @@ -323,7 +323,7 @@ impl GenomeBuilder<Vec<bool>> for BinaryEncodedGenomeBuilder {
where
R: Rng + Sized,
{
(0..self.genome_length).map(|_| rng.gen()).collect()
(0..self.genome_length).map(|_| rng.random()).collect()
}
}

Expand Down Expand Up @@ -363,7 +363,7 @@ where
R: Rng + Sized,
{
(0..self.genome_length)
.map(|_| rng.gen_range(self.min_value.clone()..self.max_value.clone()))
.map(|_| rng.random_range(self.min_value.clone()..self.max_value.clone()))
.collect()
}
}
Expand Down
12 changes: 6 additions & 6 deletions src/random/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
//! values for specific purposes.

pub use rand::{
distributions::{uniform::SampleUniform, Open01},
distr::{uniform::SampleUniform, Open01},
seq::SliceRandom,
Rng, SeedableRng,
};
Expand All @@ -19,8 +19,8 @@ pub type Seed = <Prng as SeedableRng>::Seed;

/// Generates a random seed to initialize the `Prng`.
pub fn random_seed() -> Seed {
let mut rng = Prng::from_entropy();
rng.gen()
let mut rng = Prng::from_os_rng();
rng.random()
}

/// Returns a new `Prng` initialized with the given seed.
Expand All @@ -42,7 +42,7 @@ pub fn random_index_from_range<R>(rng: &mut R, min: usize, max: usize) -> usize
where
R: Rng + Sized,
{
rng.gen_range(min..max)
rng.random_range(min..max)
}

/// Generates two cut points for a slice of given length using the given `Prng`.
Expand All @@ -64,8 +64,8 @@ where
assert!(max >= min + 4);
let max_slice = max - min - 2;
loop {
let cutpoint1 = rng.gen_range(min..max);
let cutpoint2 = rng.gen_range(min..max);
let cutpoint1 = rng.random_range(min..max);
let cutpoint2 = rng.random_range(min..max);
if cutpoint1 < cutpoint2 {
if cutpoint2 - cutpoint1 >= max_slice {
continue;
Expand Down
2 changes: 1 addition & 1 deletion src/random/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,7 @@ mod weighted_distribution {

let mut counter = vec![0, 0, 0, 0];
for _ in 0..n_sum {
let random = rng.gen::<f64>() * weighted_distribution.sum();
let random = rng.random::<f64>() * weighted_distribution.sum();
let index = weighted_distribution.select(random);
counter[index] += 1;
}
Expand Down
4 changes: 2 additions & 2 deletions src/recombination/discrete.rs
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ where
// for each value in the genotype
for locus in 0..genome_length {
// pick the value of a randomly chosen parent
let random = rng.gen_range(0..num_parents);
let random = rng.random_range(0..num_parents);
let value = parents[random][locus].clone();
genome.push(value);
}
Expand Down Expand Up @@ -254,7 +254,7 @@ where
let mut p_index = num_parents;
loop {
loop {
let index = rng.gen_range(0..num_parents);
let index = rng.random_range(0..num_parents);
if index != p_index {
p_index = index;
break;
Expand Down
6 changes: 3 additions & 3 deletions src/types/fmt/tests.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
use super::*;
use chrono::Duration;
use chrono::{Duration, TimeDelta};
use galvanic_assert::matchers::*;

#[test]
Expand All @@ -10,15 +10,15 @@ fn duration_fmt_zero() {
#[test]
fn duration_fmt_max() {
assert_that!(
&Duration::max_value().fmt(),
&TimeDelta::MAX.fmt(),
eq("15250284452w 3d 7h 12m 55s".to_string())
);
}

#[test]
fn duration_fmt_min() {
assert_that!(
&Duration::min_value().fmt(),
&TimeDelta::MIN.fmt(),
eq("-15250284452w 3d 7h 12m 55s".to_string())
);
}
Expand Down
2 changes: 1 addition & 1 deletion tests/population_builder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ fn create_population_of_custom_genotype_uniform_at_random() {
(0..8)
.map(|row| Pos {
x: row,
y: rng.gen_range(0..8),
y: rng.random_range(0..8),
})
.collect()
}
Expand Down