pub fn gen_flag(vals: &[u64], bitmask: bool) -> u64 {
    let mut rng = thread_rng();
    let extra_vals = || MAGIC64.iter().copied();

    let mut val = 0;
    if !bitmask {
        if rng.gen_ratio(5, 1000) {
            if rng.gen::<bool>() {
                val
            } else {
                rng.gen::<u64>()
            }
        } else if rng.gen_ratio(1, 100) {
            extra_vals().choose(&mut rng).unwrap()
        } else {
            let vals = extra_vals().chain(vals.iter().copied());
            let mut val = vals.choose(&mut rng).unwrap();
            if rng.gen_ratio(1, 10) {
                val ^= MAGIC64.iter().copied().choose(&mut rng).unwrap();
            }
            val
        }
    } else {
        let mut t = 0.8;
        while val == 0 || rng.gen_bool(t) {
            let mut flag = if !vals.is_empty() && rng.gen_ratio(8, 10) {
                vals.iter().copied().choose(&mut rng).unwrap()
            } else {
                extra_vals().choose(&mut rng).unwrap()
            };
            if rng.gen_ratio(5, 100) {
                if rng.gen::<bool>() {
                    flag >>= 1;
                } else {
                    flag <<= 1;
                }
            }
            val ^= flag;
            t /= 2.0;
        }
        val
    }
}
/// Generate a random flag value.
Generate a random flag value.
Generate a random flag value .
pub fn gen_flag(vals: &[u64], bitmask: bool) -> u64 {
    let mut rng = thread_rng();
    let extra_vals = || MAGIC64.iter().copied();
    let mut val = 0;
    if !bitmask {
        if rng.gen_ratio(5, 1000) {
            if rng.gen::<bool>() {
                val
            } else {
                rng.gen::<u64>()
            }
        } else if rng.gen_ratio(1, 100) {
            extra_vals().choose(&mut rng).unwrap()
        } else {
            let vals = extra_vals().chain(vals.iter().copied());
            let mut val = vals.choose(&mut rng).unwrap();
            if rng.gen_ratio(1, 10) {
                val ^= MAGIC64.iter().copied().choose(&mut rng).unwrap();
            }
            val
        }
    } else {
        let mut t = 0.8;
        while val == 0 || rng.gen_bool(t) {
            let mut flag = if !vals.is_empty() && rng.gen_ratio(8, 10) {
                vals.iter().copied().choose(&mut rng).unwrap()
            } else {
                extra_vals().choose(&mut rng).unwrap()
            };
            if rng.gen_ratio(5, 100) {
                if rng.gen::<bool>() {
                    flag >>= 1;
                } else {
                    flag <<= 1;
                }
            }
            val ^= flag;
            t /= 2.0;
        }
        val
    }
}
pub fn gen_flag ( vals : & [ u64 ] , bitmask : bool ) -> u64 { let mut rng = thread_rng ( ) ; let extra_vals = | | MAGIC64 . iter ( ) . copied ( ) ; let mut val = 0 ; if ! bitmask { if rng . gen_ratio ( 5 , 1000 ) { if rng . gen :: < bool > ( ) { val } else { rng . gen :: < u64 > ( ) } } else if rng . gen_ratio ( 1 , 100 ) { extra_vals ( ) . choose ( & mut rng ) . unwrap ( ) } else { let vals = extra_vals ( ) . chain ( vals . iter ( ) . copied ( ) ) ; let mut val = vals . choose ( & mut rng ) . unwrap ( ) ; if rng . gen_ratio ( 1 , 10 ) { val ^= MAGIC64 . iter ( ) . copied ( ) . choose ( & mut rng ) . unwrap ( ) ; } val } } else { let mut t = 0.8 ; while val == 0 || rng . gen_bool ( t ) { let mut flag = if ! vals . is_empty ( ) && rng . gen_ratio ( 8 , 10 ) { vals . iter ( ) . copied ( ) . choose ( & mut rng ) . unwrap ( ) } else { extra_vals ( ) . choose ( & mut rng ) . unwrap ( ) } ; if rng . gen_ratio ( 5 , 100 ) { if rng . gen :: < bool > ( ) { flag >>= 1 ; } else { flag <<= 1 ; } } val ^= flag ; t /= 2.0 ; } val } }
Generate a random flag value.
Generate a random flag value .
vals
&[u64]
bitmask
bool
vals
&[u64]
bitmask
bool