Skip to content

Commit

Permalink
Initial convertion from rand-0.4 to rand-0.5
Browse files Browse the repository at this point in the history
  • Loading branch information
rfdonnelly committed Mar 29, 2018
1 parent 3eda57d commit 5c8f82a
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 7 deletions.
2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ keywords = ["random", "c-api", "dsl"]

[dependencies]
rvs-parser = { version = "0.4", path = "parser" }
rand = "0.4"
rand = "0.5.0-pre.0"
linked-hash-map = "0.5"

[workspace]
Expand Down
21 changes: 19 additions & 2 deletions src/transform/rand.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ use rand::{self, Rng, SeedableRng};
pub type CrateRng = rand::XorShiftRng;

#[derive(Clone)]
pub struct Seed([u32; 4]);
pub struct Seed([u8; 16]);

impl Seed {
/// Generates a 128-bit seed from a 32-bit seed
Expand Down Expand Up @@ -34,7 +34,24 @@ impl Seed {
}

pub fn from_u32_array(x: [u32; 4]) -> Seed {
Seed(x)
Seed([
(x[0] >> 0) as u8,
(x[0] >> 8) as u8,
(x[0] >> 16) as u8,
(x[0] >> 24) as u8,
(x[1] >> 0) as u8,
(x[1] >> 8) as u8,
(x[1] >> 16) as u8,
(x[1] >> 24) as u8,
(x[2] >> 0) as u8,
(x[2] >> 8) as u8,
(x[2] >> 16) as u8,
(x[2] >> 24) as u8,
(x[3] >> 0) as u8,
(x[3] >> 8) as u8,
(x[3] >> 16) as u8,
(x[3] >> 24) as u8,
])
}

pub fn to_rng(&self) -> CrateRng {
Expand Down
6 changes: 3 additions & 3 deletions src/types/range.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@ use std::fmt;
use std::u32;
use rand::Rng;
use rand::distributions::Range as RandRange;
use rand::distributions::Sample;
use rand::distributions::IndependentSample;
use rand::distributions::{Sample, IndependentSample};
use rand::distributions::range::RangeInt;

use transform::CrateRng;
use model::{Expr, ExprData};
Expand All @@ -18,7 +18,7 @@ pub struct Range {

#[derive(Clone)]
pub struct RandRangeInclusive {
range: RandRange<u32>,
range: RandRange<RangeInt<u32>>,
use_range: bool,
offset: bool,
}
Expand Down
3 changes: 2 additions & 1 deletion src/types/weighted.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,15 @@ use model::{Expr, ExprData};

use rand::Rng;
use rand::distributions::{Range, Sample};
use rand::distributions::range::RangeInt;
use std::fmt;

#[derive(Clone)]
pub struct WeightedWithReplacement {
data: ExprData,
weights: Vec<u32>,
children: Vec<Box<Expr>>,
range: Range<usize>,
range: Range<RangeInt<usize>>,
pool: Vec<usize>,
pool_index: Option<usize>,
}
Expand Down

0 comments on commit 5c8f82a

Please sign in to comment.