MCPcopy Create free account
hub / github.com/FuzzAnything/PromptFuzz / random_sample

Function random_sample

src/program/rand.rs:26–34  ·  view source on GitHub ↗
(seq: &[T], n: usize)

Source from the content-addressed store, hash-verified

24}
25
26pub fn random_sample<T: Clone>(seq: &[T], n: usize) -> Vec<&T> {
27 if seq.len() <= n {
28 let sample: Vec<&T> = seq.iter().collect();
29 return sample;
30 }
31 let mut rng = get_global_rng();
32 let sample: Vec<&T> = seq.choose_multiple(&mut *rng, n).collect();
33 sample
34}
35
36pub fn weighted_choose(weights: Vec<f32>) -> usize {
37 if weights.iter().all(|x| *x == 0.0_f32) {

Callers 1

dump_func_gadgets_tostrFunction · 0.85

Calls 1

get_global_rngFunction · 0.85

Tested by

no test coverage detected