MCPcopy Create free account
hub / github.com/ciphermodelabs/ciphercore / get_random_value

Method get_random_value

ciphercore-base/src/random.rs:74–97  ·  view source on GitHub ↗
(&mut self, t: Type)

Source from the content-addressed store, hash-verified

72 }
73
74 pub fn get_random_value(&mut self, t: Type) -> Result<Value> {
75 match t {
76 Type::Scalar(_) | Type::Array(_, _) => {
77 let bit_size = get_size_in_bits(t)?;
78 let byte_size = (bit_size + 7) / 8;
79 // the last random byte should contain bits_to_flush zeros
80 let bits_to_flush = 8 * byte_size - bit_size;
81 let mut bytes = self.get_random_bytes(byte_size as usize)?;
82 // Remove unused random bits
83 if !bytes.is_empty() {
84 *bytes.last_mut().unwrap() >>= bits_to_flush;
85 }
86 Ok(Value::from_bytes(bytes))
87 }
88 Type::Tuple(_) | Type::Vector(_, _) | Type::NamedTuple(_) => {
89 let ts = get_types_vector(t)?;
90 let mut v = vec![];
91 for sub_t in ts {
92 v.push(self.get_random_value((*sub_t).clone())?)
93 }
94 Ok(Value::from_vector(v))
95 }
96 }
97 }
98
99 // Generates a random 64-bit integer modulo a given modulus.
100 // To avoid modulo bias, rejection sampling is performed.

Callers 15

test_prng_random_valueFunction · 0.80
test_128_bitFunction · 0.80
shard_to_sharesMethod · 0.80
test_secret_sharingFunction · 0.80
test_inputFunction · 0.80
prepare_inputFunction · 0.80
test_large_vec_sortFunction · 0.80
shard_to_sharesMethod · 0.80
test_secret_sharingFunction · 0.80

Calls 6

get_size_in_bitsFunction · 0.85
get_types_vectorFunction · 0.85
get_random_bytesMethod · 0.80
is_emptyMethod · 0.80
cloneMethod · 0.80
pushMethod · 0.45

Tested by 9

test_prng_random_valueFunction · 0.64
test_128_bitFunction · 0.64
test_secret_sharingFunction · 0.64
test_inputFunction · 0.64
test_large_vec_sortFunction · 0.64
test_secret_sharingFunction · 0.64
test_ndarrayFunction · 0.64
test_cuckoo_hashFunction · 0.64