prngtest

prngtest.monobit(bits)

Proportion of zeros and ones is compared to expected 1:1 ratio

Parameters

bits (str | Iterable[int] | bitarray) – Input sequence. If a str, must contain only "0" or "1". If an iterable of integers, must contain only 0 or 1.

Returns

  • statistic (float) – The test’s statistic.

  • p (float) – The test’s p-value.

prngtest.blockfreq(bits, blocksize=None)

Proportion of values per block is compared to expected 1:1 ratio

Parameters
  • bits (str | Iterable[int] | bitarray) – Input sequence. If a str, must contain only "0" or "1". If an iterable of integers, must contain only 0 or 1.

  • blocksize (Optional[int]) – Size of the blocks that partition the given sequence. If None, a suitable default will be found.

Returns

  • statistic (float) – The test’s statistic.

  • p (float) – The test’s p-value.

prngtest.runs(bits)

Number of runs is compared to expected result

Parameters

bits (str | Iterable[int] | bitarray) – Input sequence. If a str, must contain only "0" or "1". If an iterable of integers, must contain only 0 or 1.

Returns

  • statistic (int) – The test’s statistic.

  • p (float) – The test’s p-value.

prngtest.blockruns(bits)

Longest runs per block is compared to expected result

Parameters

bits (str | Iterable[int] | bitarray) – Input sequence. If a str, must contain only "0" or "1". If an iterable of integers, must contain only 0 or 1.

Returns

  • statistic (float) – The test’s statistic.

  • p (float) – The test’s p-value.

prngtest.matrix(bits, nrows=None, ncols=None)

Independence of neighbouring subsequences is compared to expected result

Parameters
  • bits (str | Iterable[int] | bitarray) – Input sequence. If a str, must contain only "0" or "1". If an iterable of integers, must contain only 0 or 1.

  • nrows (Optional[int]) – Number of rows in each matrix. If None, a suitable default will be found.

  • ncols (Optional[int]) – Number of columns in each matrix. If None, a suitable default will be found.

Returns

  • statistic (float) – The test’s statistic.

  • p (float) – The test’s p-value.

prngtest.spectral(bits)

Potency of periodic features in sequence is compared to expected result

Parameters

bits (str | Iterable[int] | bitarray) – Input sequence. If a str, must contain only "0" or "1". If an iterable of integers, must contain only 0 or 1.

Returns

  • statistic (float) – The test’s statistic.

  • p (float) – The test’s p-value.

prngtest.notm(bits, tempsize=None, blocksize=None)

Matches to template per block is compared to expected result

Parameters
  • bits (str | Iterable[int] | bitarray) – Input sequence. If a str, must contain only "0" or "1". If an iterable of integers, must contain only 0 or 1.

  • tempsize (Optional[int]) – Size of template. If None, a suitable default will be found.

  • blocksize (Optional[int]) – Size of the blocks that partition the given sequence. If None, a suitable default will be found.

Returns

results_map (dict[frozenbitarray, tuple[float, float]]) – Mapping of each template to a tuple containing its respective test statistic and p-value.

prngtest.otm(bits, tempsize=None, blocksize=None)

Overlapping matches to template per block is compared to expected result

Parameters
  • bits (str | Iterable[int] | bitarray) – Input sequence. If a str, must contain only "0" or "1". If an iterable of integers, must contain only 0 or 1.

  • tempsize (Optional[int]) – Size of template. If None, a suitable default will be found.

  • blocksize (Optional[int]) – Size of the blocks that partition the given sequence. If None, a suitable default will be found.

Returns

  • statistic (float) – The test’s statistic.

  • p (float) – The test’s p-value.

prngtest.universal(bits, blocksize=None, init_nblocks=None)

Distance between patterns is compared to expected result

Parameters
  • bits (str | Iterable[int] | bitarray) – Input sequence. If a str, must contain only "0" or "1". If an iterable of integers, must contain only 0 or 1.

  • blocksize (Optional[int]) – Size of the blocks that partition the given sequence. If None, a suitable default will be found.

  • init_nblocks (Optional[int]) – Number of blocks to be used in identifying patterns, beginning at the start of the sequence. If None, a suitable default will be found.

Returns

  • statistic (float) – The test’s statistic.

  • p (float) – The test’s p-value.

prngtest.complexity(bits, blocksize=None)

LSFRs of blocks is compared to expected length

Parameters
  • bits (str | Iterable[int] | bitarray) – Input sequence. If a str, must contain only "0" or "1". If an iterable of integers, must contain only 0 or 1.

  • blocksize (Optional[int]) – Size of the blocks that partition the given sequence. If None, a suitable default will be found.

Returns

  • statistic (float) – The test’s statistic.

  • p (float) – The test’s p-value.

prngtest.serial(bits, blocksize=None)

Proportion of all overlapping patterns is compared to expected uniformity

Parameters
  • bits (str | Iterable[int] | bitarray) – Input sequence. If a str, must contain only "0" or "1". If an iterable of integers, must contain only 0 or 1.

  • blocksize (Optional[int]) – Size of the blocks that partition the given sequence. If None, a suitable default will be found.

Returns

  • first_result (tuple[float, float]) – The first test’s statistic and p-value.

  • second_result (tuple[float, float]) – The second test’s statistic and p-value.

prngtest.apen(bits, blocksize=None)

Approximate entropy of sequence is compared to expected result

Parameters
  • bits (str | Iterable[int] | bitarray) – Input sequence. If a str, must contain only "0" or "1". If an iterable of integers, must contain only 0 or 1.

  • blocksize (Optional[int]) – Size of the blocks that partition the given sequence. If None, a suitable default will be found.

Returns

  • statistic (float) – The test’s statistic.

  • p (float) – The test’s p-value.

prngtest.cumsum(bits, reverse=False)

Furthest detour in a randomn walk is compared to expected result

Parameters
  • bits (str | Iterable[int] | bitarray) – Input sequence. If a str, must contain only "0" or "1". If an iterable of integers, must contain only 0 or 1.

  • reverse (bool) – If True, cumulate from the end of the sequence first.

Returns

  • statistic (int) – The test’s statistic.

  • p (float) – The test’s p-value.

prngtest.excursions(bits)

Frequency of states per cycle in a random walk is compared to expected results

Parameters

bits (str | Iterable[int] | bitarray) – Input sequence. If a str, must contain only "0" or "1". If an iterable of integers, must contain only 0 or 1.

Returns

results_map (dict[int, tuple[float, float]]) – Mapping of each state to a tuple containing its respective test statistic and p-value.

prngtest.vexcursions(bits)

Proportion of states in a random walk is compared to expected results

Parameters

bits (str | Iterable[int] | bitarray) – Input sequence. If a str, must contain only "0" or "1". If an iterable of integers, must contain only 0 or 1.

Returns

results_map (dict[int, tuple[float, float]]) – Mapping of each state to a tuple containing its respective test statistic and p-value.