#[test] fn test_zero() { // Test that APIs are happy with zero-length requests
getrandom_impl(&mut [0u8; 0]).unwrap();
}
// Return the number of bits in which s1 and s2 differ #[cfg(not(feature = "custom"))] fn num_diff_bits(s1: &[u8], s2: &[u8]) -> usize {
assert_eq!(s1.len(), s2.len());
s1.iter()
.zip(s2.iter())
.map(|(a, b)| (a ^ b).count_ones() as usize)
.sum()
}
// Tests the quality of calling getrandom on two large buffers #[test] #[cfg(not(feature = "custom"))] fn test_diff() { letmut v1 = [0u8; 1000];
getrandom_impl(&mut v1).unwrap();
// Between 3.5 and 4.5 bits per byte should differ. Probability of failure: // ~ 2^(-94) = 2 * CDF[BinomialDistribution[8000, 0.5], 3500] let d = num_diff_bits(&v1, &v2);
assert!(d > 3500);
assert!(d < 4500);
}
// Tests the quality of calling getrandom repeatedly on small buffers #[test] #[cfg(not(feature = "custom"))] fn test_small() { // For each buffer size, get at least 256 bytes and check that between // 3 and 5 bits per byte differ. Probability of failure: // ~ 2^(-91) = 64 * 2 * CDF[BinomialDistribution[8*256, 0.5], 3*256] for size in1..=64 { letmut num_bytes = 0; letmut diff_bits = 0; while num_bytes < 256 { letmut s1 = vec![0u8; size];
getrandom_impl(&mut s1).unwrap(); letmut s2 = vec![0u8; size];
getrandom_impl(&mut s2).unwrap();
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.