File tree Expand file tree Collapse file tree 1 file changed +17
-3
lines changed Expand file tree Collapse file tree 1 file changed +17
-3
lines changed Original file line number Diff line number Diff line change 1+ //! Show the output of the random number generator
2+
3+ use core:: ffi:: c_int;
4+
15fn main ( ) {
26 let mut distribution = std:: collections:: BTreeMap :: new ( ) ;
7+ let mut min = c_int:: MAX ;
8+ let mut max = c_int:: MIN ;
39
410 let mut seedp = 1 ;
5- for _ in 0 ..4 {
6- println ! ( "." ) ;
11+ for i in 0 ..40 {
12+ println ! ( "{}/40" , i ) ;
713 for _ in 0 ..1_000_000 {
814 let random = unsafe { tinyrlibc:: rand_r ( & mut seedp) } ;
15+ if random > max {
16+ max = random;
17+ }
18+ if random < min {
19+ min = random;
20+ }
921 for place in 0 ..core:: ffi:: c_int:: BITS {
1022 let random_bit = ( random & ( 1 << place) ) != 0 ;
1123 if random_bit {
@@ -18,7 +30,9 @@ fn main() {
1830 }
1931 }
2032
33+ println ! ( "Min value: {min:#10x}" ) ;
34+ println ! ( "Max value: {max:#10x}" ) ;
2135 for ( k, v) in distribution. iter ( ) {
22- println ! ( "{:02} => {} " , k, v) ;
36+ println ! ( "Bit {:02} was set {} times " , k, v) ;
2337 }
2438}
You can’t perform that action at this time.
0 commit comments