pub fn entropy<F: Float + FromPrimitive>(data: &[u8]) -> FExpand description
Calculates the Shannon entropy of a byte slice.
Shannon entropy measures the average information content per byte, ranging from 0 (completely uniform) to 8 (maximum randomness).
§Arguments
data- A byte slice to analyze
§Returns
The entropy value in bits per byte (0.0 to 8.0)
§Example
§Calculating entropy of a Vec
use shannon::entropy;
let uniform_data = vec![0u8; 100];
let e: f64 = entropy(&uniform_data);
assert_eq!(e, 0.0);§Calculating entropy per character of a String
use shannon::entropy;
let text = String::from("AABB");
let e: f64 = entropy(text.as_bytes());
assert_eq!(e, 1.0);