Skip to content

Commit

Permalink
fix: also shuffle language before cycling
Browse files Browse the repository at this point in the history
Fixes #58.
  • Loading branch information
max-niederman committed Aug 14, 2022
1 parent 8be215c commit ea43969
Showing 1 changed file with 5 additions and 3 deletions.
8 changes: 5 additions & 3 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -86,19 +86,21 @@ impl Opt {
.map(|f| f.data.into_owned())
})?;

let language: Vec<&str> = str::from_utf8(&bytes)
let mut rng = thread_rng();

let mut language: Vec<&str> = str::from_utf8(&bytes)
.expect("Language file had non-utf8 encoding.")
.lines()
.collect();
language.shuffle(&mut rng);

let mut contents: Vec<_> = language
.into_iter()
.cycle()
.take(self.words.get())
.map(ToOwned::to_owned)
.collect();

contents.shuffle(&mut thread_rng());
contents.shuffle(&mut rng);

Some(contents)
}
Expand Down

0 comments on commit ea43969

Please sign in to comment.