Skip to content
Merged
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
2 changes: 1 addition & 1 deletion src/distributions/weighted_index.rs
Original file line number Diff line number Diff line change
Expand Up @@ -161,7 +161,7 @@ impl<X: SampleUniform + PartialOrd> WeightedIndex<X> {
if *w < zero {
return Err(WeightedError::InvalidWeight);
}
if i >= self.cumulative_weights.len() + 1 {
if i > self.cumulative_weights.len() {
return Err(WeightedError::TooMany);
}

Expand Down
7 changes: 4 additions & 3 deletions src/rngs/mock.rs
Original file line number Diff line number Diff line change
Expand Up @@ -72,13 +72,14 @@ impl RngCore for StepRng {

#[cfg(test)]
mod tests {
use super::*;

#[test]
#[cfg(feature = "serde1")]
fn test_serialization_step_rng() {
use super::StepRng;

let some_rng = StepRng::new(42, 7);
let de_some_rng: StepRng = bincode::deserialize(&bincode::serialize(&some_rng).unwrap()).unwrap();
let de_some_rng: StepRng =
bincode::deserialize(&bincode::serialize(&some_rng).unwrap()).unwrap();
assert_eq!(some_rng.v, de_some_rng.v);
assert_eq!(some_rng.a, de_some_rng.a);

Expand Down
7 changes: 6 additions & 1 deletion src/seq/index.rs
Original file line number Diff line number Diff line change
Expand Up @@ -85,10 +85,15 @@ impl IndexVec {
IndexVec::USize(ref v) => IndexVecIter::USize(v.iter()),
}
}
}

impl IntoIterator for IndexVec {
type Item = usize;
type IntoIter = IndexVecIntoIter;

/// Convert into an iterator over the indices as a sequence of `usize` values
#[inline]
pub fn into_iter(self) -> IndexVecIntoIter {
fn into_iter(self) -> IndexVecIntoIter {
match self {
IndexVec::U32(v) => IndexVecIntoIter::U32(v.into_iter()),
IndexVec::USize(v) => IndexVecIntoIter::USize(v.into_iter()),
Expand Down
22 changes: 9 additions & 13 deletions src/seq/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -44,13 +44,11 @@ use crate::Rng;
/// ```
/// use rand::seq::SliceRandom;
///
/// fn main() {
/// let mut rng = rand::thread_rng();
/// let mut bytes = "Hello, random!".to_string().into_bytes();
/// bytes.shuffle(&mut rng);
/// let str = String::from_utf8(bytes).unwrap();
/// println!("{}", str);
/// }
/// let mut rng = rand::thread_rng();
/// let mut bytes = "Hello, random!".to_string().into_bytes();
/// bytes.shuffle(&mut rng);
/// let str = String::from_utf8(bytes).unwrap();
/// println!("{}", str);
/// ```
/// Example output (non-deterministic):
/// ```none
Expand Down Expand Up @@ -228,12 +226,10 @@ pub trait SliceRandom {
/// ```
/// use rand::seq::IteratorRandom;
///
/// fn main() {
/// let mut rng = rand::thread_rng();
///
/// let faces = "😀😎😐😕😠😢";
/// println!("I am {}!", faces.chars().choose(&mut rng).unwrap());
/// }
/// let mut rng = rand::thread_rng();
///
/// let faces = "😀😎😐😕😠😢";
/// println!("I am {}!", faces.chars().choose(&mut rng).unwrap());
/// ```
/// Example output (non-deterministic):
/// ```none
Expand Down