You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
ilo-pali-pi-nimi-sin/src/lipu_nimi.rs

33 lines
1.1 KiB

use rand::seq::SliceRandom;
pub fn pana_lipu(i: usize, j: usize) -> Vec<String> {
let lipu_nimi = std::fs::read_to_string("nimi_ale.txt").unwrap();
let mut kulupu_nimi = Vec::new();
for nanpa in i..j+1 {
for nimi in lipu_nimi.lines().nth(nanpa).unwrap().split_whitespace() {
kulupu_nimi.push(String::from(nimi));
}
}
kulupu_nimi
}
pub fn pana(i: &[usize]) -> String {
let lipu_nimi = std::fs::read_to_string("nimi_ale.txt").unwrap();
let mut kulupu_nimi = Vec::new();
for nanpa in i {
for nimi in lipu_nimi.lines().nth(*nanpa).unwrap().split_whitespace() {
kulupu_nimi.push(String::from(nimi));
}
}
String::clone(kulupu_nimi.choose(&mut rand::thread_rng()).unwrap())
}
pub fn pana_lili(i: &[usize]) -> char {
let lipu_nimi = std::fs::read_to_string("nimi_ale.txt").unwrap();
let mut kulupu_nimi = Vec::new();
for nanpa in i {
for nimi in lipu_nimi.lines().nth(*nanpa).unwrap().split_whitespace() {
kulupu_nimi.push(nimi.chars().nth(0).unwrap());
}
}
*kulupu_nimi.choose(&mut rand::thread_rng()).unwrap()
}