# (map_bytes_to_double bytes) # Map the series of byte values (numbers in the range 0 to 255) into a double- # precision floating point value. # # Test vectors: # [0 0 0 0 0 0 0] => 0 # [255 255 255 255 255 255 63] => 0.25 # [255 255 255 255 255 255 127] => 0.5 # [255 255 255 255 255 255 191] => 0.75 # [255 255 255 255 255 255 255] => 1 \map_bytes_to_double=(fold (\x\b / (+ x b) 256) 0) # Get a random double-precision floating point value in the range 0 to 1 # inclusive. \\random_double= ( \bytes=(map ord; str_bytes; random_bytes 7) map_bytes_to_double bytes )