Puid.Entropy (puid v2.0.5)
Entropy related calculations
The implementation is based on mathematical approximations to the solution of what is often referred to as the Birthday Problem.
Link to this section Summary
Functions
Entropy bits for generating a total
number of events with the given risk
of repeat
Entropy bits for a binary of length len
comprised of chars
characters.
Same as Puid.Entropy.bits_for_len/2
but either returns bits or raises a
Puid.Error
Entropy bits per chars
character.
Same as bits_per_char/1
but either returns bits or raises a Puid.Error
Length needed for a string generated from chars
to have entropy bits
.
Same as Puid.Entropy.len_for_bits/2
but either returns len or raises a
Puid.Error
Link to this section Types
puid_chars()
@type puid_chars() :: Puid.Chars.puid_chars()
Link to this section Functions
bits(total, risk)
@spec bits(non_neg_integer(), non_neg_integer()) :: float()
Entropy bits for generating a total
number of events with the given risk
of repeat
The total size of the event pool is 2<sup>bits</sup>.
example
Example
iex> Puid.Entropy.bits(10.0e6, 1.0e12)
85.37013046707142
bits_for_len(chars, len)
@spec bits_for_len(puid_chars(), non_neg_integer()) :: {:ok, non_neg_integer()} | Puid.Error.t()
Entropy bits for a binary of length len
comprised of chars
characters.
chars
must be valid as per Chars.charlist/1
.
example
Example
iex> Puid.Entropy.bits_for_len(:alphanum, 14)
{:ok, 83}
iex> Puid.Entropy.bits_for_len('dingosky', 14)
{:ok, 42}
bits_for_len!(chars, len)
@spec bits_for_len!(puid_chars(), non_neg_integer()) :: non_neg_integer()
Same as Puid.Entropy.bits_for_len/2
but either returns bits or raises a
Puid.Error
example
Example
iex> Puid.Entropy.bits_for_len!(:alphanum, 14)
83
iex> Puid.Entropy.bits_for_len!("dingosky", 14)
42
bits_per_char(chars)
@spec bits_per_char(puid_chars()) :: {:ok, float()} | Puid.Error.t()
Entropy bits per chars
character.
chars
must be valid as per Chars.charlist/1
.
example
Example
iex> Puid.Entropy.bits_per_char(:alphanum)
{:ok, 5.954196310386875}
iex> Puid.Entropy.bits_per_char("dingosky")
{:ok, 3.0}
bits_per_char!(chars)
@spec bits_per_char!(puid_chars()) :: float()
Same as bits_per_char/1
but either returns bits or raises a Puid.Error
example
Example
iex> Puid.Entropy.bits_per_char!(:alphanum)
5.954196310386875
Puid.Entropy.bits_per_char!("dingosky")
3.0
len_for_bits(chars, bits)
@spec len_for_bits(puid_chars(), non_neg_integer()) :: {:ok, non_neg_integer()} | Puid.Error.t()
Length needed for a string generated from chars
to have entropy bits
.
chars
must be valid as per Chars.charlist/1
.
example
Example
iex> Puid.Entropy.len_for_bits(:alphanum, 128)
{:ok, 22}
iex> Puid.Entropy.len_for_bits("dingosky", 128)
{:ok, 43}
len_for_bits!(chars, bits)
@spec len_for_bits!(puid_chars(), non_neg_integer()) :: non_neg_integer() | Puid.Error.t()
Same as Puid.Entropy.len_for_bits/2
but either returns len or raises a
Puid.Error
example
Example
iex> Puid.Entropy.len_for_bits!(:alphanum, 128)
22
iex> Puid.Entropy.len_for_bits!('dingosky', 128)
43