Skip to content

Commit

Permalink
fix: randomize entire language before taking words
Browse files Browse the repository at this point in the history
  • Loading branch information
max-niederman committed Dec 19, 2021
1 parent 408f96d commit 28bc60b
Showing 1 changed file with 12 additions and 11 deletions.
23 changes: 12 additions & 11 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -70,22 +70,23 @@ impl Opt {
Resources::get(&format!("language/{}", self.language))
.map(|f| f.data.into_owned())
})?;
let language: Vec<&str> = str::from_utf8(&bytes)

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

let mut words: Vec<String> = language
.into_iter()
.cycle()
.take(self.words.into())
.map(String::from)
.collect();

let mut rng = thread_rng();
words.shuffle(&mut rng);

Some(words)
language.shuffle(&mut rng);

Some(
language
.into_iter()
.cycle()
.take(self.words.into())
.map(String::from)
.collect(),
)
}
}
}
Expand Down

0 comments on commit 28bc60b

Please sign in to comment.