adv_random will create random numbers or strings based off a rule or multiple rules. It comes out the box with standard rules and also supports you creating your own rules too.
let random_result = random_numbers(&Settings::new(&[
Box::new(NumberRange::all(1, 20))
], 10));
match random_result.numbers() {
Ok(numbers) => {
println!("{:?}", numbers);
},
_ => println!("{:?}", random_result.logs())
}
let random_result = random_numbers(&Settings::new(&[
Box::new(NoDuplicate{}),
Box::new(NumberRange::all(1, 20))
], 10));
match random_result.numbers() {
Ok(numbers) => {
println!("{:?}", numbers);
},
_ => println!("{:?}", random_result.logs())
}
let random_result = random_numbers(&Settings::new(&[
Box::new(NumberRange::from_map(&[(&vec![0, 1], 100, 999), (&vec![2], 1000, 9999)]))
], 3));
match random_result.numbers() {
Ok(numbers) => {
println!("{:?}", numbers);
},
_ => println!("{:?}", random_result.logs())
}
let random_result = random_numbers(&Settings::new(&[
Box::new(NoDuplicate{}),
Box::new(NumberPool::new(&[
NumberPoolItem::new("exclude_23", &PoolType::Set(HashSet::from_iter([23])), 0),
NumberPoolItem::new("must_contain_1_4", &PoolType::Set(HashSet::from_iter([1, 4])), 2),
NumberPoolItem::new("some_set", &PoolType::Set(HashSet::from_iter([17, 18, 19, 20, 21])), 3),
])),
Box::new(NumberRange::all(1, 100)),
], 10));
match random_result.numbers() {
Ok(numbers) => {
println!("{:?}", numbers);
},
_ => println!("{:?}", random_result.logs())
}
let random_result = random_numbers(&Settings::new(&[
Box::new(NoDuplicate{}),
Box::new(NumberRange::all(1, 10)),
Box::new(OddEvenByIndex::new(&vec![0, 2, 4], &vec![1,3])),
], 5));
match random_result.numbers() {
Ok(numbers) => {
println!("{:?}", numbers);
},
_ => println!("{:?}", random_result.logs())
}
let random_result = random_numbers(&Settings::new(&[
Box::new(NoDuplicate{}),
Box::new(NumberRange::all(1, 10)),
Box::new(OddEvenByIndex::new(&vec![3,4], &vec![0, 1, 2]))
], 5));
match random_result.numbers() {
Ok(numbers) => {
println!("{:?}", numbers);
},
_ => println!("{:?}", random_result.logs())
}
let random_result = random_numbers(&Settings::new(&[
Box::new(NoDuplicate{}),
Box::new(NumberRange::all(1, 10)),
Box::new(OddEvenByIndex::new(&vec![4], &vec![]))
], 5));
match random_result.numbers() {
Ok(numbers) => {
println!("{:?}", numbers);
},
_ => println!("{:?}", random_result.logs())
}
let random_result = random_numbers(&Settings::new(&[
Box::new(NoDuplicate{}),
Box::new(NumberRange::all(1, 20)),
Box::new(OddEven::new(5, 5))
], 10));
match random_result.numbers() {
Ok(numbers) => {
println!("{:?}", numbers);
},
_ => println!("{:?}", random_result.logs())
}
let random_result = random_numbers(&Settings::new(&[
Box::new(NumberRange::all(1, 20)),
Box::new(OddEven::new(0, 10))
], 10));
match random_result.numbers() {
Ok(numbers) => {
println!("{:?}", numbers);
},
_ => println!("{:?}", random_result.logs())
}
let random_result = random_numbers(&Settings::new(&[
Box::new(NoDuplicate{}),
Box::new(NumberRange::all(1, 10)),
Box::new(Sequential::new(5, &[]))
], 5));
match random_result.numbers() {
Ok(numbers) => {
println!("{:?}", numbers);
},
_ => println!("{:?}", random_result.logs())
}
let random_result = random_numbers(&Settings::new(&[
Box::new(NoDuplicate{}),
Box::new(NumberRange::all(1, 10)),
Box::new(Sequential::new(3, &[2]))
], 5));
match random_result.numbers() {
Ok(numbers) => {
println!("{:?}", numbers);
},
_ => println!("{:?}", random_result.logs())
}
let random_result = random_numbers(&Settings::new(&[
Box::new(NoDuplicate{}),
Box::new(NumberRange::all(1, 10)),
Box::new(Sequential::new(1, &[2, 2]))
], 5));
match random_result.numbers() {
Ok(numbers) => {
println!("{:?}", numbers);
},
_ => println!("{:?}", random_result.logs())
}
let random_result = random_numbers(&Settings::new(&[
Box::new(NumberPool::alphanumeric(20, false))
], 20));
match random_result.string(true) {
Ok(numbers) => {
println!("{:?}", numbers);
},
_ => println!("{:?}", random_result.logs())
}
let random_result = random_numbers(&Settings::new(&[
Box::new(NumberPool::alphanumeric(20, true))
], 20));
match random_result.string(true) {
Ok(numbers) => {
println!("{:?}", numbers);
},
_ => println!("{:?}", random_result.logs())
}
let random_result = random_numbers(&Settings::new(&[
Box::new(NoDuplicate{}),
Box::new(NumberPool::alphanumeric_specs(10, 10, 0))
], 20));
match random_result.string(true) {
Ok(numbers) => {
println!("{:?}", numbers);
},
_ => println!("{:?}", random_result.logs())
}
let random_result = random_numbers(&Settings::new(&[
Box::new(NoDuplicate{}),
Box::new(NumberPool::alphanumeric_specs(10, 10, 5))
], 25));
match random_result.string(true) {
Ok(numbers) => {
println!("{:?}", numbers);
},
_ => println!("{:?}", random_result.logs())
}
let random_result = random_numbers(&Settings::new(&[
Box::new(NumberPool::new(&[
NumberPoolItem::new("upper_case_alpha_set", &PoolType::new(&"ABCDEFGHIJKLMNOPQRSTUVWXYZ".chars().collect()), 11),
NumberPoolItem::new("numeric_set", &PoolType::new(&"365".chars().collect()), 2),
NumberPoolItem::new("special_char_set", &PoolType::new(&"#*".chars().collect()), 2),
]))
], 15));
match random_result.string(true) {
Ok(numbers) => {
println!("{:?}", numbers);
},
_ => println!("{:?}", random_result.logs())
}
let uc_alpha_set: HashSet<char> = "ABCDEFGHIJKLMNOPQRSTUVWXYZ".chars().collect();
let random_result = random_numbers(&Settings::new(&[
Box::new(ExcludeNumberSets::new_string(&HashSet::from_iter(vec![String::from("AB1234567"), String::from("CB1234567")]))),
Box::new(NumberPoolByIndex::new(vec![
NumberPoolItemByIndex::new("upper_case_alpha_set", &PoolType::new(&uc_alpha_set.clone()), &HashSet::from_iter(vec![0, 1])),
NumberPoolItemByIndex::new("numeric_set", &PoolType::new(&"1234567890".chars().collect()), &HashSet::from_iter(vec![2, 3, 4, 5, 6, 7, 8])),
]))
], 9));
match random_result.string(false) {
Ok(numbers) => {
println!("{:?}", numbers);
},
_ => println!("{:?}", random_result.logs())
}
let random_result = random_numbers(&Settings::new(&[
Box::new(NumberRange::all(1, 100)),
Box::new(NumberSpace::new(NumberSpaceType::Lt, 3))
], 10));
match random_result.numbers() {
Ok(numbers) => {
let mut sorted_numbers: Vec<usize> = numbers.to_vec();
sorted_numbers.sort_unstable();
println!("{:?}", sorted_numbers);
},
_ => println!("{:?}", random_result.logs())
}
let random_result = random_numbers(&Settings::new(&[
Box::new(NumberRange::all(1, 100)),
Box::new(NumberSpace::new(NumberSpaceType::Lte, 3))
], 10));
match random_result.numbers() {
Ok(numbers) => {
let mut sorted_numbers: Vec<usize> = numbers.to_vec();
sorted_numbers.sort_unstable();
println!("{:?}", sorted_numbers);
},
_ => println!("{:?}", random_result.logs())
}
let random_result = random_numbers(&Settings::new(&[
Box::new(NumberRange::all(1, 100)),
Box::new(NumberSpace::new(NumberSpaceType::Eq, 3))
], 10));
match random_result.numbers() {
Ok(numbers) => {
let mut sorted_numbers: Vec<usize> = numbers.to_vec();
sorted_numbers.sort_unstable();
println!("{:?}", sorted_numbers);
},
_ => println!("{:?}", random_result.logs())
}
let random_result = random_numbers(&Settings::new(&[
Box::new(NumberRange::all(1, 100)),
Box::new(NumberSpace::new(NumberSpaceType::Gte, 3))
], 10));
match random_result.numbers() {
Ok(numbers) => {
let mut sorted_numbers: Vec<usize> = numbers.to_vec();
sorted_numbers.sort_unstable();
println!("{:?}", sorted_numbers);
},
_ => println!("{:?}", random_result.logs())
}
let random_result = random_numbers(&Settings::new(&[
Box::new(NumberRange::all(1, 100)),
Box::new(NumberSpace::new(NumberSpaceType::Gt, 3))
], 10));
match random_result.numbers() {
Ok(numbers) => {
let mut sorted_numbers: Vec<usize> = numbers.to_vec();
sorted_numbers.sort_unstable();
println!("{:?}", sorted_numbers);
},
_ => println!("{:?}", random_result.logs())
}