UtilStringCalculateStringEntropy Method
Calculates the entropy of a string based on the Shannon's entropy formula.
The entropy is a measure of the amount of uncertainty or randomness in a set of characters.
Namespace: DevCase.Core.DataProcessing.CommonAssembly: DevCase.net48 (in DevCase.net48.dll) Version: 6.0.0.0 (6.0)
XMLNS for XAML: Not mapped to an xmlns.
public static double CalculateStringEntropy(
string str
)
Public Shared Function CalculateStringEntropy (
str As String
) As Double
Dim str As String
Dim returnValue As Double
returnValue = UtilString.CalculateStringEntropy(str)
public:
static double CalculateStringEntropy(
String^ str
)
static member CalculateStringEntropy :
str : string -> float
No code example is currently available or this language may not be supported.
- str String
-
The input string.
Double
A number representing the entropy value of the input string.
A higher entropy value indicates that the text contains more randomness or unpredictability,
while a lower entropy value indicates that the text is more structured or predictable.
To calculate the entropy of the given text, the algorithm first counts the frequency of each character in the text.
It then uses these frequencies to calculate the probability of each character appearing in the text.
Once the probability of each character is known, the algorithm applies Shannon's entropy formula,
which looks like this: H = -Σp(x)log2p(x), where H is the entropy, p(x) is the probability that
character x will appear in the text, and log2 is the base 2 logarithm.