Custom Random Value Generators
Project description
Fortuna: A Collection of Random Value Generators for Python3
Fortuna's main goal is to provide a quick and easy way to build custom random-value functions for your data. Fortuna also offers a variety of high-performance dice functions.
The core functionality of Fortuna is based on the Storm c++ library. While Storm has a high quality, hardware seeded random engine - it is not appropriate for cryptography of any kind. Fortuna is meant for games, data science, A.I. and experimental programming, not security.
Quick Install $ pip install Fortuna
Installation may require the following:
- Python 3.6 or later with dev tools (setuptools, pip, etc.)
- Cython: Bridge from C/C++ to Python.
- Modern C++17 Compiler and Standard Library.
Sister Projects (included but documented separately):
- RNG: Python3 API for the C++ Random Library. https://pypi.org/project/RNG/
- Pyewacket: Drop-in replacement for the Python3 random module. https://pypi.org/project/Pyewacket/
- MonkeyScope: Framework for testing non-deterministic functions. https://pypi.org/project/MonkeyScope/
Table of Contents:
- Numeric Limits
- Project Terminology
- Random Generator Functions:
- Value Generators
RandomValue(Collection) -> Callable -> Value
TruffleShuffle(Collection) -> Callable -> Value
QuantumMonty(Collection) -> Callable -> Value
CumulativeWeightedChoice(Table) -> Callable -> Value
RelativeWeightedChoice(Table) -> Callable -> Value
FlexCat(Matrix) -> Callable -> Value
- Integer Generators
random_below(Integer) -> Integer
random_int(Integer, Integer) -> Integer
random_range(Integer, Integer, Integer) -> Integer
d(Integer) -> Integer
dice(Integer, Integer) -> Integer
plus_or_minus(Integer) -> Integer
plus_or_minus_linear(Integer) -> Integer
plus_or_minus_gauss(Integer) -> Integer
- Index Generators:
- ZeroCool Specification:
f(N) -> [0, N)
orf(-N) -> [-N, 0)
random_index(Integer) -> Integer
front_gauss(Integer) -> Integer
middle_gauss(Integer) -> Integer
back_gauss(Integer) -> Integer
quantum_gauss(Integer) -> Integer
front_poisson(Integer) -> Integer
middle_poisson(Integer) -> Integer
back_poisson(Integer) -> Integer
quantum_poisson(Integer) -> Integer
front_linear(Integer) -> Integer
middle_linear(Integer) -> Integer
back_linear(Integer) -> Integer
quantum_linear(Integer) -> Integer
quantum_monty(Integer) -> Integer
- ZeroCool Specification:
- Float Generators
canonical() -> Float
random_float(Float, Float) -> Float
triangular(Float, Float, Float) -> Float
- Boolean Generator
percent_true(Float) -> Boolean
- Inplace Shuffle (Knuth B)
shuffle(List) -> None
- Utilities
flatten(Object, *args, Boolean, **kwargs) -> Object
smart_clamp(Integer, Integer, Integer) -> Integer
- Value Generators
- Development Log
- Test Suite Output
- Legal Information
Numeric Limits:
- Integer: 64 bit signed integer.
- Range: ±9223372036854775807, approximately ±9.2 billion billion
- Float: 64 bit floating point.
- Range: ±1.7976931348623157e+308
- Epsilon Delta: 5e-305 to 5e-324, platform dependant
Project Terminology:
- Value: Almost any object in Python can be considered a Value.
- Expressions, Generators, and F-strings can be wrapped in a lambda for dynamic evaluation. This is highly recommended.
- Callable: Any callable object, function, method or lambda.
- Collection: Any Iterable group of Values.
- List, Tuple, Set, etc...
- Fortuna classes that wrap a Collection can wrap any Iterable including Iterators and Generators.
- Sequence: An ordered, random access group of Values.
- List, tuple or list comprehension.
- Fortuna functions that take a Collection as input will always require a proper Sequence. They will not accept raw Iterators, you must convert them to list first.
- Pair: Collection of two Values.
- Table: Collection of Pairs.
- Matrix: Dictionary of Collections.
- Inclusive Range.
[1, 10] -> 1, 2, 3, 4, 5, 6, 7, 8, 9, 10
- Partially Exclusive Ranges.
[1, 11) -> 1, 2, 3, 4, 5, 6, 7, 8, 9, 10
(0, 10] -> 1, 2, 3, 4, 5, 6, 7, 8, 9, 10
- Automatic Flattening.
- Works with: RandomValue, TruffleShuffle, QuantumMonty, WeightedChoice & FlexCat.
- Lazy Evaluation. All Random Value Generator Classes in Fortuna will recursively call or "flatten" callable objects returned from the data at call time, so long as all required parameters are provided.
- Mixing callable objects with un-callable objects is fully supported, but can become messy.
- Nested callable objects are fully supported. Because
lambda(lambda) -> lambda
fixes everything for arbitrary values of 'because', 'fixes' and 'everything'. - To disable flattening, pass the optional keyword argument
flat=False
to the constructor during instantiation.
Random Value Engines
Fortuna.RandomValue
Fortuna.RandomValue(collection: Collection, zero_cool=random_index, flat=True) -> Callable -> Value
Random Value Engine Class that supports dependency injection.
- @param collection :: Collection of Values. Tuple recommended.
- @param zero_cool :: Optional ZeroCool Method, kwarg only. Default = random_index(). This function must follow the ZeroCool Spec.
- @param flat :: Bool. Default: True. Option to automatically flatten callable values with lazy evaluation.
- @return :: Callable Object.
Callable(*args, **kwargs) -> Value
- Default = 0, kwarg only. Parameter for ZeroCool Method.range_to=0
indicates the intent to use the whole collection.- @param *args, **kwargs :: Optional arguments used to flatten the return Value (below) if Callable.
- @return Value or Value(*args, **kwargs) if the value itself is callable. This is recursive.
RandomValue Dependency Injection Example
from Fortuna import RandomValue, front_linear, back_linear
# Data Setup
random_apple = RandomValue((
"Delicious",
"Empire",
"Granny Smith",
"Honey Crisp",
"Macintosh",
), zero_cool=front_linear)
random_fruit = RandomValue((
lambda: f"Apple, {random_apple()}",
"Banana",
"Cherry",
"Grapes",
"Orange",
), zero_cool=back_linear)
# Usage
print(random_fruit())
# prints a random fruit with the correct distributions
RandomValue with Auto Flattening
Auto Flattening work with all random generator classes in Fortuna.
from Fortuna import RandomValue
auto_flat = RandomValue([lambda: 1, lambda: 2, lambda: 3])
print(auto_flat()) # will print the value 1, 2 or 3.
# Note: the lambda will not be called until call time and stays dynamic for the life of the object.
auto_flat_with = RandomValue([lambda x: x, lambda x: x + 1, lambda x: x + 2])
print(auto_flat_with(2)) # will print the value 2, 3 or 4
# Note: if this is called with no args it will simply return the lambda in an uncalled state.
un_flat = RandomValue([lambda: 1, lambda: 2, lambda: 3], flat=False)
print(un_flat()()) # will print the value 1, 2 or 3,
# mind the double-double parenthesis, they are required to manually unpack the lambdas
auto_un_flat = RandomValue([lambda x: x, lambda x: x + 1, lambda x: x + 2], flat=False)
# Note: flat=False is not required here because the lambdas can not be called without input x satisfied.
# It is recommended to specify flat=False if non-flat output is intended.
print(auto_un_flat()(1)) # will print the value 1, 2 or 3, mind the double-double parenthesis
Mixing Static Objects with Callable Objects
Auto Flattening work with all random generator classes in Fortuna.
from Fortuna import RandomValue
""" With automatic flattening active, `lambda() -> int` can be treated as an `int`. """
mixed_flat = RandomValue([1, 2, lambda: 3])
print(mixed_flat()) # will print 1, 2 or 3
""" Mixed Anti-pattern """
mixed_un_flat = RandomValue([1, 2, lambda: 3], flat=False) # this is not recommended.
print(mixed_flat()) # will print 1, 2 or "Function <lambda at some_address>"
# This pattern is not recommended because you wont know the nature of what you get back.
# This is almost always not what you want, and it can give rise to messy logic in other areas of your code.
Dynamic Strings
To successfully express a dynamic string, and keep it dynamic for the duration of the program, at least one level of indirection is required. Without a lambda - the f-string would collapse into a static string too soon. This works with all random generator classes in Fortuna.
from Fortuna import RandomValue, d
# d() is a simple dice function, d(n) -> [1, n] flat uniform distribution.
dynamic_string = RandomValue((
# while the probability of all A == all B == all C, individual probabilities of each possible string will differ based on the number of possible outputs of each category.
lambda: f"A{d(2)}", # -> A1 - A2, each are twice as likely as any particular B, and three times as likely as any C.
lambda: f"B{d(4)}", # -> B1 - B4, each are half as likely as any particular A, and 3/2 as likely as any C.
lambda: f"C{d(6)}", # -> C1 - C6, each are 1/3 as likely as any particular A and 2/3 as likely of any B.
))
print(dynamic_string()) # prints a random dynamic string, generated at call time.
Nesting Dolls
This works with all random generator classes in Fortuna.
from Fortuna import RandomValue
# Data Setup
nesting_dolls = RandomValue((
RandomValue(("A", "B", "C", "D", "E")),
RandomValue(("F", "G", "H", "I", "J")),
RandomValue(("K", "L", "M", "N", "O")),
RandomValue(("P", "Q", "R", "S", "T")),
))
# Usage
print(nesting_dolls())
# prints one of the letters A-T, flat uniform distribution of each category and within each category.
TruffleShuffle
Fortuna.TruffleShuffle(collection: Collection, flat=True) -> Callable -> Value
- @param collection :: Collection of Values. Set recommended but not required.
- @param flat :: Bool. Default: True. Option to automatically flatten callable values with lazy evaluation.
- @return :: Callable Object.
Callable(*args, **kwargs) -> Value
- @param *args, **kwargs :: Optional arguments used to flatten the return Value (below) if Callable.
- @return :: Random value from the collection with a Wide Uniform Distribution.
Wide Uniform Distribution: "Wide" refers to the average distance between consecutive occurrences of the same value. The average width of the output distribution will naturally scale up with the size of the collection. The goal of this type of distribution is to keep the output sequence free of clumps or streaks of the same value, while maintaining randomness and uniform probability. This is not the same as a flat uniform distribution. The two distributions over time will be statistically similar for any given set, but the repetitiveness of the output sequence will be very different.
TruffleShuffle, Basic Use
from Fortuna import TruffleShuffle
# Data Setup
list_of_values = { 1, 2, 3, 4, 5, 6 }
truffle_shuffle = TruffleShuffle(list_of_values)
# Usage
print(truffle_shuffle()) # this will print one of the numbers 1-6,
# repeated calls will produce a wide distribution.
QuantumMonty
Fortuna.QuantumMonty(collection: Collection, flat=True) -> Callable -> Value
- @param collection :: Collection of Values. Tuple recommended.
- @param flat :: Bool. Default: True. Option to automatically flatten callable values with lazy evaluation.
- @return :: Callable Object with Monty Methods for producing various distributions of the data.
- @param *args, **kwargs :: Optional arguments used to flatten the return Value (below) if Callable.
- @return :: Random value from the data. The instance will produce random values from the list using the selected distribution model or "monty". The default monty is the Quantum Monty Algorithm.
from Fortuna import QuantumMonty
# Data Setup
list_of_values = [1, 2, 3, 4, 5, 6]
monty = QuantumMonty(list_of_values)
# Usage
print(monty()) # prints a random value from the list_of_values.
# uses the default Quantum Monty Algorithm.
print(monty.flat_uniform()) # prints a random value from the list_of_values.
# uses the "flat_uniform" monty.
# equivalent to random.choice(list_of_values).
The QuantumMonty class represents a diverse collection of strategies for producing random values from a sequence where the output distribution is based on the method you choose. Generally speaking, each value in the sequence will have a probability that is based on its position in the sequence. For example: the "front" monty produces random values where the beginning of the sequence is geometrically more common than the back. Given enough samples the "front" monty will always converge to a 45 degree slope down for any list of unique values.
There are three primary method families: linear, gaussian, and poisson. Each family has three base methods; 'front', 'middle', 'back', plus a 'quantum' method that incorporates all three base methods. The quantum algorithms for each family produce distributions by overlapping the probability waves of the other methods in their family. The Quantum Monty Algorithm incorporates all nine base methods.
import Fortuna
# Data Setup
monty = Fortuna.QuantumMonty(
["Alpha", "Beta", "Delta", "Eta", "Gamma", "Kappa", "Zeta"]
)
# Usage
# Each of the following methods will return a random value from the sequence.
# Each method has its own unique distribution model.
""" Flat Base Case """
monty.flat_uniform() # Flat Uniform Distribution
""" Geometric Positional """
monty.front_linear() # Linear Descending, Triangle
monty.middle_linear() # Linear Median Peak, Equilateral Triangle
monty.back_linear() # Linear Ascending, Triangle
monty.quantum_linear() # Linear Overlay, 3-way monty.
""" Gaussian Positional """
monty.front_gauss() # Front Gamma
monty.middle_gauss() # Scaled Gaussian
monty.back_gauss() # Reversed Gamma
monty.quantum_gauss() # Gaussian Overlay, 3-way monty.
""" Poisson Positional """
monty.front_poisson() # 1/4 Mean Poisson
monty.middle_poisson() # 1/2 Mean Poisson
monty.back_poisson() # 3/4 Mean Poisson
monty.quantum_poisson() # Poisson Overlay, 3-way monty.
""" Quantum Monty Algorithm """
monty() # Quantum Monty Algorithm, 9-way monty.
monty.quantum_monty() # same as above
Weighted Choice: Base Class
Weighted Choice offers two strategies for selecting random values from a sequence where programmable rarity is desired. Both produce a custom distribution of values based on the weights of the values.
The choice to use one strategy over the other is purely about which one suits you or your data best. Relative weights are easier to understand at a glance. However, many RPG Treasure Tables map rather nicely to a cumulative weighted strategy.
Cumulative Weighted Choice
Fortuna.CumulativeWeightedChoice(weighted_table: Table, flat=True) -> Callable -> Value
- @param weighted_table :: Table of weighted pairs. Tuple of Tuples recommended.
- @param flat :: Bool. Default: True. Option to automatically flatten callable values with lazy evaluation.
- @return :: Callable Instance
- @param *args, **kwargs :: Optional arguments used to flatten the return Value (below) if Callable.
- @return :: Random value from the weighted_table, distribution based on the weights of the values.
Note: Logic dictates Cumulative Weights must be unique!
from Fortuna import CumulativeWeightedChoice
# Data Setup
cum_weighted_choice = CumulativeWeightedChoice((
(7, "Apple"),
(11, "Banana"),
(13, "Cherry"),
(23, "Grape"),
(26, "Lime"),
(30, "Orange"), # same as relative weight 4 because 30 - 26 = 4
))
# Usage
print(cum_weighted_choice()) # prints a weighted random value
Relative Weighted Choice
Fortuna.RelativeWeightedChoice(weighted_table: Table) -> Callable -> Value
- @param weighted_table :: Table of weighted pairs. Tuple of Tuples recommended.
- @param flat :: Bool. Default: True. Option to automatically flatten callable values with lazy evaluation.
- @return :: Callable Instance
- @param *args, **kwargs :: Optional arguments used to flatten the return Value (below) if Callable.
- @return :: Random value from the weighted_table, distribution based on the weights of the values.
from Fortuna import RelativeWeightedChoice
# Data
population = ["Apple", "Banana", "Cherry", "Grape", "Lime", "Orange"]
rel_weights = [7, 4, 2, 10, 3, 4]
# Setup
rel_weighted_choice = RelativeWeightedChoice(zip(rel_weights, population))
# Usage
print(rel_weighted_choice()) # prints a weighted random value
FlexCat
Fortuna.FlexCat(matrix_data: Matrix, key_bias="front_linear", val_bias="truffle_shuffle", flat=True) -> Callable -> Value
- @param matrix_data :: Dictionary of Sequences.
- @parm key_bias :: Default is "front_linear". String indicating the name of the algorithm to use for random key selection.
- @parm val_bias :: Default is "truffle_shuffle". String indicating the name of the algorithm to use for random value selection.
- @param flat :: Bool. Default is True. Option to automatically flatten callable values with lazy evaluation.
- @return :: Callable Instance
- @param cat_key :: Optional String. Default is None. Key selection by name. If specified, this will override the key_bias for a single call.
- @param *args, **kwargs :: Optional arguments used to flatten the return Value (below) if Callable.
- @return :: Value. Returns a random value generated with val_bias from a random sequence generated with key_bias.
FlexCat is like a multi dimensional QuantumMonty.
The constructor takes two optional keyword arguments to specify the algorithms to be used to make random selections. The algorithm specified for selecting a key need not be the same as the one for selecting values. An optional key may be provided at call time to bypass the random key selection. Keys passed in this way must exactly match a key in the Matrix.
By default, FlexCat will use key_bias="front_linear" and val_bias="truffle_shuffle", this will make the top of the data structure geometrically more common than the bottom and it will truffle shuffle the sequence values. This config is known as TopCat, it produces a descending-step, micro-shuffled distribution sequence. Many other combinations are available.
Algorithmic Options: See QuantumMonty & TruffleShuffle for more details.
- "front_linear", Linear Descending
- "middle_linear", Linear Median Peak
- "back_linear", Linear Ascending
- "quantum_linear", Linear 3-way monty
- "front_gauss", Gamma Descending
- "middle_gauss", Scaled Gaussian
- "back_gauss", Gamma Ascending
- "quantum_gauss", Gaussian 3-way monty
- "front_poisson", Front 1/3 Mean Poisson
- "middle_poisson", Middle Mean Poisson
- "back_poisson", Back 1/3 Mean Poisson
- "quantum_poisson", Poisson 3-way monty
- "quantum_monty", Quantum Monty Algorithm, 9-way monty
- "flat_uniform", uniform flat distribution
- "truffle_shuffle", TruffleShuffle wide uniform distribution
from Fortuna import FlexCat, d
# |- Collection Generator, does not require lambda.
# Data |
matrix_data = {# $ |- Dynamic Value Expression
"Cat_A": (f"A{i}" for i in range(1, 6)), # | Lazy, 1 of 4 possibilities
"Cat_B": ("B1", "B2", "B3", "B4", "B5"), # $ lambda required for dynamic eval
"Cat_C": ("C1", "C2", "C3", f"C4.{d(2)}", lambda: f"C5.{d(4)}"),
}# $ $ $ $ $
# | | |- Value | |- Fair die method: d4
# | | |
# | |- Collection |- Static Value Expression
# | | Eager, 1 or 2 permanently
# |- Collection Key, "cat_key"
# |- Collection Algorithm |- Value Algorithm
# Setup $ y-axis $ x-axis
flex_cat = FlexCat(matrix_data, key_bias="front_linear", val_bias="flat_uniform")
# $ $ $
# | | |- Dictionary of Collections
# | |
# | |- FlexCat Constructor
# |
# |- Callable Random Value Generator
# Usage
flex_cat() # returns a Value from the Matrix.
flex_cat(cat_key="Cat_B") # returns a Value specifically from the "Cat_B" Collection.
Random Integer Generators
Fortuna.random_below(number: int) -> int
- @param number :: Any Integer
- @return :: Returns a random integer in the range...
random_below(number) -> [0, number)
for positive values.random_below(number) -> (number, 0]
for negative values.random_below(0) -> 0
Always returns zero when input is zero
- Flat uniform distribution.
Fortuna.random_int(left_limit: int, right_limit: int) -> int
- @param left_limit :: Any Integer
- @param right_limit :: Any Integer
- @return :: Returns a random integer in the range [left_limit, right_limit]
random_int(1, 10) -> [1, 10]
random_int(10, 1) -> [1, 10]
same as above.random_int(A, B)
Always returns A when A == B
- Flat uniform distribution.
Fortuna.random_range(start: int, stop: int = 0, step: int = 1) -> int
- @param start :: Required starting point.
random_range(0) -> [0]
random_range(10) -> [0, 10)
from 0 to 9. Same asFortuna.random_index(N)
random_range(-10) -> [-10, 0)
from -10 to -1. Same asFortuna.random_index(-N)
- @param stop :: Zero by default. Optional range bound. With at least two arguments, the order of the first two does not matter.
random_range(0, 0) -> [0]
random_range(0, 10) -> [0, 10)
from 0 to 9.random_range(10, 0) -> [0, 10)
same as above.
- @param step :: One by default. Optional step size.
random_range(0, 0, 0) -> [0]
random_range(0, 10, 2) -> [0, 10) by 2
even numbers from 0 to 8.- The sign of the step parameter controls the phase of the output. Negative stepping will flip the inclusively.
random_range(0, 10, -1) -> (0, 10]
starts at 10 and ranges down to 1.random_range(10, 0, -1) -> (0, 10]
same as above.random_range(10, 10, 0) -> [10]
step size or range size of zero always returns the first parameter.
- @return :: Returns a random integer in the range [A, B) by increments of C.
- Flat uniform distribution.
Fortuna.d(sides: int) -> int
- Represents a single roll of a given size die.
- @param sides :: Represents the size or number of sides, most commonly six.
- @return :: Returns a random integer in the range [1, sides].
- Flat uniform distribution.
Fortuna.dice(rolls: int, sides: int) -> int
- Represents the sum total of multiple rolls of the same size die.
- @param rolls :: Represents the number of times to roll the die.
- @param sides :: Represents the die size or number of sides, most commonly six.
- @return :: Returns a random integer in range [X, Y] where X = rolls and Y = rolls * sides.
- Geometric distribution based on the number and size of the dice rolled.
- Complexity scales primarily with the number of rolls, not the size of the dice.
Fortuna.plus_or_minus(number: int) -> int
- @param number :: input to determine the output distribution range.
- @return :: Returns a random integer in range [-number, number].
- Flat uniform distribution.
Fortuna.plus_or_minus_linear(number: int) -> int
- @param number :: input to determine the output distribution range.
- @return :: Returns a random integer in range [-number, number].
- Linear geometric, 45 degree triangle distribution centered on zero.
Fortuna.plus_or_minus_gauss(number: int) -> int
- @param number :: input to determine the output distribution range.
- @return :: Returns a random integer in range [-number, number].
- Stretched gaussian distribution centered on zero.
Random Index, ZeroCool Specification
ZeroCool Methods are used to generate random Sequence indices.
ZeroCool methods must have the following properties:
- Any distribution model is acceptable such that...
- The method or function must take exactly one Integer parameter N.
- The method returns a random int in range
[0, N)
for positive values of N. - The method returns a random int in range
[N, 0)
for negative values of N. - This symmetry matches how python can index a list from the back for negative values or the front for positive values of N.
from Fortuna import random_index
some_list = [i for i in range(100)] # [0..99]
print(some_list[random_index(10)]) # prints one of the first 10 items of some_list, [0, 9]
print(some_list[random_index(-10)]) # prints one of the last 10 items of some_list, [90, 99]
ZeroCool Methods
Fortuna.random_index(size: int) -> int
Flat uniform distributionFortuna.front_gauss(size: int) -> int
Gamma Distribution: Front PeakFortuna.middle_gauss(size: int) -> int
Stretched Gaussian Distribution: Median PeakFortuna.back_gauss(size: int) -> int
Gamma Distribution: Back PeakFortuna.quantum_gauss(size: int) -> int
Quantum Gaussian: Three-way MontyFortuna.front_poisson(size: int) -> int
Poisson Distribution: Front 1/3 PeakFortuna.middle_poisson(size: int) -> int
Poisson Distribution: Middle PeakFortuna.back_poisson(size: int) -> int
Poisson Distribution: Back 1/3 PeakFortuna.quantum_poisson(size: int) -> int
Quantum Poisson: Three-way MontyFortuna.front_geometric(size: int) -> int
Linear Geometric: 45 Degree Front PeakFortuna.middle_geometric(size: int) -> int
Linear Geometric: 45 Degree Middle PeakFortuna.back_geometric(size: int) -> int
Linear Geometric: 45 Degree Back PeakFortuna.quantum_geometric(size: int) -> int
Quantum Geometric: Three-way MontyFortuna.quantum_monty(size: int) -> int
Quantum Monty: Nine-way Monty
from Fortuna import front_gauss, middle_gauss, back_gauss, quantum_gauss
some_list = [i for i in range(100)]
# Each of the following prints one of the first 10 items of some_list with the appropriate distribution
print(some_list[front_gauss(10)])
print(some_list[middle_gauss(10)])
print(some_list[back_gauss(10)])
print(some_list[quantum_gauss(10)])
# Each of the following prints one of the last 10 items of some_list with the appropriate distribution
print(some_list[front_gauss(-10)])
print(some_list[middle_gauss(-10)])
print(some_list[back_gauss(-10)])
print(some_list[quantum_gauss(-10)])
Random Float Generators
Fortuna.canonical() -> float
- @return :: random float in range [0.0, 1.0), flat uniform.
Fortuna.random_float(a: Float, b: Float) -> Float
- @param a :: Float input
- @param b :: Float input
- @return :: random Float in range [a, b), flat uniform distribution.
Fortuna.triangular(low Float, high Float, mode Float) -> Float
- @param low :: Float, minimum output
- @param high :: Float, maximum output
- @param mode :: Float, most common output, mode must be in range
[low, high]
- @return :: random number in range
[low, high]
with a linear distribution about the mode.
Random Truth Generator
Fortuna.percent_true(truth_factor: Float = 50.0) -> bool
- @param truth_factor :: The probability of True as a percentage. Default is 50 percent.
- @return :: Produces True or False based on the truth_factor as a percent of true.
- Always returns False if num is 0 or less
- Always returns True if num is 100 or more.
Shuffle Algorithm
Fortuna.shuffle(array: list) -> None
- Knuth B Shuffle Algorithm. Destructive, in-place shuffle.
- @param array :: List to be shuffled.
- @return :: None
Fortuna.knuth_a(array: list) -> None
- Knuth A Shuffle Algorithm. Destructive, in-place shuffle.
- @param array :: List to be shuffled.
- @return :: None
Fortuna.fisher_yates(array: list) -> None
- Fisher Yates Shuffle Algorithm. Destructive, in-place shuffle.
- @param array :: List to be shuffled.
- @return :: None
Utilities
Fortuna.flatten(maybe_callable, *args, flat=True, **kwargs) -> flatten(maybe_callable(*args, **kwargs))
- Recursively calls the input object and returns the result. The arguments are only passed in on the first evaluation.
- If the maybe_callable is not callable it is simply returned without error.
- Conceptually this is somewhat like collapsing the wave function. Often used as the last step in lazy evaluation.
- @param maybe_callable :: Any Object that might be callable.
- @param flat :: Boolean, default is True. Optional, keyword only.
- Disables flattening if flat is set to False, conceptually turns flatten into the identity function.
- @param *args, **kwargs :: Optional arguments used to flatten the maybe_callable object.
- @return :: Recursively Flattened Object.
Fortuna.smart_clamp(target: int, lo: int, hi: int) -> int
- Used to clamp the target in range [lo, hi] by saturating the bounds.
- Essentially the same as median for exactly three integers.
- @return :: Returns the middle value, input order does not matter.
MultiChoice
Fortuna.MultiChoice(
query: str,
*,
options: Iterable<str> = (),
default: str = "",
strict: bool = False,
cursor: str = ">>>",
) -> str
Generates multiple-choice questions for user input on the terminal. If there is no user input and options is not empty and there's no default - a random choice will be made from the options, otherwise the default will be used. If there is no user input and there are no options and no default - the question will be repeated. If strict is set to true - the user input string must be in the options, or the question will be repeated. Options are stored lowercase and printed title case. User input is not case sensitive.
- @param query: String.
- Question for the user.
- @param options: Optional Iterable of Strings. Default=()
- Options presented to the user as a numbered sequence.
- The user may enter an answer as text or by number.
- @param default: Optional String.
- This is used if no user input is provided.
- If no default is provided a random choice will be made.
- @param strict: Optional Bool. Default=False
- True: Answer must be in the options tuple. Not case-sensitive.
- False: Accepts any answer.
- @param cursor: Optional String. Default='>>>'
- Indicates user input field.
Fortuna Development Log
Fortuna 3.14.0
- Minor TruffleShuffle Update
- Fisher Yates, and Knuth A Shuffle Algorithms added for comparison with Fortuna.shuffle()
- Some platforms may prefer one over another. Intel favors Knuth B by more than double.
Fortuna 3.13.0 - Internal
- Development & Testing Environment Updated to Python 3.8
- Python3.8 brings a 10-20% performance boost over all.
- RandomValue API redesign. Dependency Injection is now handled at instantiation rather than call time.
Fortuna 3.12.2
- Installer update.
- Clarified the docs for MultiChoice.
Fortuna 3.12.1
- MultiChoice now accepts a default.
Fortuna 3.12.0
- MultiChoice added
Fortuna 3.10.2
- Doc string update for clarity.
- Test update
- MonkeyScope Update
Fortuna 3.10.1
- Documentation fix, RandomValue examples are now together.
Fortuna 3.10.0
- Fortuna now includes both RNG and Pyewacket.
- Documentation update.
Fortuna 3.9.11
- Installer Update, properly installs MonkeyScope as intended.
Fortuna 3.9.10
- Fixed Typos
Fortuna 3.9.9
- Docs Update
Fortuna 3.9.8
- Test Update
Fortuna 3.9.7
- Tests for RNG and Pyewacket are now included in
fortuna_extras
package.
Fortuna 3.9.6
- Documentation update.
Fortuna 3.9.5
- Storm 3.2.2 Update.
Fortuna 3.9.4
- Documentation update.
Fortuna 3.9.3
- MonkeyScope update, 10% test suite performance improvement.
Fortuna 3.9.2
- Documentation update.
Fortuna 3.9.1
flatten_with
has been renamed toflatten
. This should be non-breaking, please report any bugs.
Fortuna 3.9.0 - Internal
- Added many doc strings.
- Corrected many typos in Docs.
- The
flatten
function has been fully replaced byflatten_with
.- All classes that support automatic flattening can now accept arbitrary arguments at call time.
flatten_with
will be renamed toflatten
in a future release.
Fortuna 3.8.9
- Fixed some typos.
Fortuna 3.8.8
- Fortuna now supports Python notebooks, python3.6 or higher required.
Fortuna 3.8.7
- Storm Update
Fortuna 3.8.6
- Attempting to make Fortuna compatible with Python Notebooks.
Fortuna 3.8.5
- Installer Config Update
Fortuna 3.8.4
- Installer Config Update
Fortuna 3.8.3
- Storm Update 3.2.0
Fortuna 3.8.2
- More Typo Fix
Fortuna 3.8.1
- Typo Fix
Fortuna 3.8.0
- Major API Update, several utilities have been deprecated. See MonkeyScope for replacements.
- distribution
- distribution_timer
- timer
Fortuna 3.7.7
- Documentation Update
Fortuna 3.7.6
- Install script update.
Fortuna 3.7.5 - internal
- Storm 3.1.1 Update
- Added triangular function.
Fortuna 3.7.4
- Fixed: missing header in the project manifest, this may have caused building from source to fail.
Fortuna 3.7.3
- Storm Update
Fortuna 3.7.2
- Storm Update
Fortuna 3.7.1
- Bug fixes
Fortuna 3.7.0 - internal
- flatten_with() is now the default flattening algorithm for all Fortuna classes.
Fortuna 3.6.5
- Documentation Update
- RandomValue: New flatten-with-arguments functionality.
Fortuna 3.6.4
- RandomValue added for testing
Fortuna 3.6.3
- Developer Update
Fortuna 3.6.2
- Installer Script Update
Fortuna 3.6.1
- Documentation Update
Fortuna 3.6.0
- Storm Update
- Test Update
- Bug fix for random_range(), negative stepping is now working as intended. This bug was introduced in 3.5.0.
- Removed Features
- lazy_cat(): use QuantumMonty class instead.
- flex_cat(): use FlexCat class instead.
- truffle_shuffle(): use TruffleShuffle class instead.
Fortuna 3.5.3 - internal
- Features added for testing & development
- ActiveChoice class
- random_rotate() function
Fortuna 3.5.2
- Documentation Updates
Fortuna 3.5.1
- Test Update
Fortuna 3.5.0
- Storm Update
- Minor Bug Fix: Truffle Shuffle
- Deprecated Features
- lazy_cat(): use QuantumMonty class instead.
- flex_cat(): use FlexCat class instead.
- truffle_shuffle(): use TruffleShuffle class instead.
Fortuna 3.4.9
- Test Update
Fortuna 3.4.8
- Storm Update
Fortuna 3.4.7
- Bug fix for analytic_continuation.
Fortuna 3.4.6
- Docs Update
Fortuna 3.4.5
- Docs Update
- Range Tests Added, see extras folder.
Fortuna 3.4.4
- ZeroCool Algorithm Bug Fixes
- Typos Fixed
Fortuna 3.4.3
- Docs Update
Fortuna 3.4.2
- Typos Fixed
Fortuna 3.4.1
- Major Bug Fix: random_index()
Fortuna 3.4.0 - internal
- ZeroCool Poisson Algorithm Family Updated
Fortuna 3.3.8 - internal
- Docs Update
Fortuna 3.3.7
- Fixed Performance Bug: ZeroCool Linear Algorithm Family
Fortuna 3.3.6
- Docs Update
Fortuna 3.3.5
- ABI Updates
- Bug Fixes
Fortuna 3.3.4
- Examples Update
Fortuna 3.3.3
- Test Suite Update
Fortuna 3.3.2 - internal
- Documentation Update
Fortuna 3.3.1 - internal
- Minor Bug Fix
Fortuna 3.3.0 - internal
- Added
plus_or_minus_gauss(N: int) -> int
random int in range [-N, N] Stretched Gaussian Distribution
Fortuna 3.2.3
- Small Typos Fixed
Fortuna 3.2.2
- Documentation update.
Fortuna 3.2.1
- Small Typo Fixed
Fortuna 3.2.0
- API updates:
- QunatumMonty.uniform -> QunatumMonty.flat_uniform
- QunatumMonty.front -> QunatumMonty.front_linear
- QunatumMonty.middle -> QunatumMonty.middle_linear
- QunatumMonty.back -> QunatumMonty.back_linear
- QunatumMonty.quantum -> QunatumMonty.quantum_linear
- randindex -> random_index
- randbelow -> random_below
- randrange -> random_range
- randint -> random_int
Fortuna 3.1.0
discrete()
has been removed, see Weighted Choice.lazy_cat()
added.- All ZeroCool methods have been raised to top level API, for use with lazy_cat()
Fortuna 3.0.1
- minor typos.
Fortuna 3.0.0
- Storm 2 Rebuild.
Fortuna 2.1.1
- Small bug fixes.
- Test updates.
Fortuna 2.1.0, Major Feature Update
- Fortuna now includes the best of RNG and Pyewacket.
Fortuna 2.0.3
- Bug fix.
Fortuna 2.0.2
- Clarified some documentation.
Fortuna 2.0.1
- Fixed some typos.
Fortuna 2.0.0b1-10
- Total rebuild. New RNG Storm Engine.
Fortuna 1.26.7.1
- README updated.
Fortuna 1.26.7
- Small bug fix.
Fortuna 1.26.6
- Updated README to reflect recent changes to the test script.
Fortuna 1.26.5
- Fixed small bug in test script.
Fortuna 1.26.4
- Updated documentation for clarity.
- Fixed a minor typo in the test script.
Fortuna 1.26.3
- Clean build.
Fortuna 1.26.2
- Fixed some minor typos.
Fortuna 1.26.1
- Release.
Fortuna 1.26.0 beta 2
- Moved README and LICENSE files into fortuna_extras folder.
Fortuna 1.26.0 beta 1
- Dynamic version scheme implemented.
- The Fortuna Extension now requires the fortuna_extras package, previously it was optional.
Fortuna 1.25.4
- Fixed some minor typos in the test script.
Fortuna 1.25.3
- Since version 1.24 Fortuna requires Python 3.7 or higher. This patch corrects an issue where the setup script incorrectly reported requiring Python 3.6 or higher.
Fortuna 1.25.2
- Updated test suite.
- Major performance update for TruffleShuffle.
- Minor performance update for QuantumMonty & FlexCat: cycle monty.
Fortuna 1.25.1
- Important bug fix for TruffleShuffle, QuantumMonty and FlexCat.
Fortuna 1.25
- Full 64bit support.
- The Distribution & Performance Tests have been redesigned.
- Bloat Control: Two experimental features have been removed.
- RandomWalk
- CatWalk
- Bloat Control: Several utility functions have been removed from the top level API. These function remain in the Fortuna namespace for now, but may change in the future without warning.
- stretch_bell, internal only.
- min_max, not used anymore.
- analytic_continuation, internal only.
- flatten, internal only.
Fortuna 1.24.3
- Low level refactoring, non-breaking patch.
Fortuna 1.24.2
- Setup config updated to improve installation.
Fortuna 1.24.1
- Low level patch to avoid potential ADL issue. All low level function calls are now qualified.
Fortuna 1.24
- Documentation updated for even more clarity.
- Bloat Control: Two naïve utility functions that are no longer used in the module have been removed.
- n_samples -> use a list comprehension instead.
[f(x) for _ in range(n)]
- bind -> use a lambda instead.
lambda: f(x)
- n_samples -> use a list comprehension instead.
Fortuna 1.23.7
- Documentation updated for clarity.
- Minor bug fixes.
- TruffleShuffle has been redesigned slightly, it now uses a random rotate instead of swap.
- Custom
__repr__
methods have been added to each class.
Fortuna 1.23.6
- New method for QuantumMonty: quantum_not_monty - produces the upside down quantum_monty.
- New bias option for FlexCat: not_monty.
Fortuna 1.23.5.1
- Fixed some small typos.
Fortuna 1.23.5
- Documentation updated for clarity.
- All sequence wrappers can now accept generators as input.
- Six new functions added:
- random_float() -> float in range [0.0..1.0) exclusive, uniform flat distribution.
- percent_true_float(num: float) -> bool, Like percent_true but with floating point precision.
- plus_or_minus_linear_down(num: int) -> int in range [-num..num], upside down pyramid.
- plus_or_minus_curve_down(num: int) -> int in range [-num..num], upside down bell curve.
- mostly_not_middle(num: int) -> int in range [0..num], upside down pyramid.
- mostly_not_center(num: int) -> int in range [0..num], upside down bell curve.
- Two new methods for QuantumMonty:
- mostly_not_middle
- mostly_not_center
- Two new bias options for FlexCat, either can be used to define x and/or y axis bias:
- not_middle
- not_center
Fortuna 1.23.4.2
- Fixed some minor typos in the README.md file.
Fortuna 1.23.4.1
- Fixed some minor typos in the test suite.
Fortuna 1.23.4
- Fortuna is now Production/Stable!
- Fortuna and Fortuna Pure now use the same test suite.
Fortuna 0.23.4, first release candidate.
- RandomCycle, BlockCycle and TruffleShuffle have been refactored and combined into one class: TruffleShuffle.
- QuantumMonty and FlexCat will now use the new TruffleShuffle for cycling.
- Minor refactoring across the module.
Fortuna 0.23.3, internal
- Function shuffle(arr: list) added.
Fortuna 0.23.2, internal
- Simplified the plus_or_minus_curve(num: int) function, output will now always be bounded to the range [-num..num].
- Function stretched_bell(num: int) added, this matches the previous behavior of an unbounded plus_or_minus_curve.
Fortuna 0.23.1, internal
- Small bug fixes and general clean up.
Fortuna 0.23.0
- The number of test cycles in the test suite has been reduced to 10,000 (down from 100,000). The performance of the pure python implementation and the c-extension are now directly comparable.
- Minor tweaks made to the examples in
.../fortuna_extras/fortuna_examples.py
Fortuna 0.22.2, experimental features
- BlockCycle class added.
- RandomWalk class added.
- CatWalk class added.
Fortuna 0.22.1
- Fortuna classes no longer return lists of values, this behavior has been extracted to a free function called n_samples.
Fortuna 0.22.0, experimental features
- Function bind added.
- Function n_samples added.
Fortuna 0.21.3
- Flatten will no longer raise an error if passed a callable item that it can't call. It correctly returns such items in an uncalled state without error.
- Simplified
.../fortuna_extras/fortuna_examples.py
- removed unnecessary class structure.
Fortuna 0.21.2
- Fix some minor bugs.
Fortuna 0.21.1
- Fixed a bug in
.../fortuna_extras/fortuna_examples.py
Fortuna 0.21.0
- Function flatten added.
- Flatten: The Fortuna classes will recursively unpack callable objects in the data set.
Fortuna 0.20.10
- Documentation updated.
Fortuna 0.20.9
- Minor bug fixes.
Fortuna 0.20.8, internal
- Testing cycle for potential new features.
Fortuna 0.20.7
- Documentation updated for clarity.
Fortuna 0.20.6
- Tests updated based on recent changes.
Fortuna 0.20.5, internal
- Documentation updated based on recent changes.
Fortuna 0.20.4, internal
- WeightedChoice (both types) can optionally return a list of samples rather than just one value, control the length of the list via the n_samples argument.
Fortuna 0.20.3, internal
- RandomCycle can optionally return a list of samples rather than just one value, control the length of the list via the n_samples argument.
Fortuna 0.20.2, internal
- QuantumMonty can optionally return a list of samples rather than just one value, control the length of the list via the n_samples argument.
Fortuna 0.20.1, internal
- FlexCat can optionally return a list of samples rather than just one value, control the length of the list via the n_samples argument.
Fortuna 0.20.0, internal
- FlexCat now accepts a standard dict as input. The ordered(ness) of dict is now part of the standard in Python 3.7.1. Previously FlexCat required an OrderedDict, now it accepts either and treats them the same.
Fortuna 0.19.7
- Fixed bug in
.../fortuna_extras/fortuna_examples.py
.
Fortuna 0.19.6
- Updated documentation formatting.
- Small performance tweak for QuantumMonty and FlexCat.
Fortuna 0.19.5
- Minor documentation update.
Fortuna 0.19.4
- Minor update to all classes for better debugging.
Fortuna 0.19.3
- Updated plus_or_minus_curve to allow unbounded output.
Fortuna 0.19.2
- Internal development cycle.
- Minor update to FlexCat for better debugging.
Fortuna 0.19.1
- Internal development cycle.
Fortuna 0.19.0
- Updated documentation for clarity.
- MultiCat has been removed, it is replaced by FlexCat.
- Mostly has been removed, it is replaced by QuantumMonty.
Fortuna 0.18.7
- Fixed some more README typos.
Fortuna 0.18.6
- Fixed some README typos.
Fortuna 0.18.5
- Updated documentation.
- Fixed another minor test bug.
Fortuna 0.18.4
- Updated documentation to reflect recent changes.
- Fixed some small test bugs.
- Reduced default number of test cycles to 10,000 - down from 100,000.
Fortuna 0.18.3
- Fixed some minor README typos.
Fortuna 0.18.2
- Fixed a bug with Fortuna Pure.
Fortuna 0.18.1
- Fixed some minor typos.
- Added tests for
.../fortuna_extras/fortuna_pure.py
Fortuna 0.18.0
- Introduced new test format, now includes average call time in nanoseconds.
- Reduced default number of test cycles to 100,000 - down from 1,000,000.
- Added pure Python implementation of Fortuna:
.../fortuna_extras/fortuna_pure.py
- Promoted several low level functions to top level.
zero_flat(num: int) -> int
zero_cool(num: int) -> int
zero_extreme(num: int) -> int
max_cool(num: int) -> int
max_extreme(num: int) -> int
analytic_continuation(func: staticmethod, num: int) -> int
min_max(num: int, lo: int, hi: int) -> int
Fortuna 0.17.3
- Internal development cycle.
Fortuna 0.17.2
- User Requested: dice() and d() functions now support negative numbers as input.
Fortuna 0.17.1
- Fixed some minor typos.
Fortuna 0.17.0
- Added QuantumMonty to replace Mostly, same default behavior with more options.
- Mostly is depreciated and may be removed in a future release.
- Added FlexCat to replace MultiCat, same default behavior with more options.
- MultiCat is depreciated and may be removed in a future release.
- Expanded the Treasure Table example in
.../fortuna_extras/fortuna_examples.py
Fortuna 0.16.2
- Minor refactoring for WeightedChoice.
Fortuna 0.16.1
- Redesigned fortuna_examples.py to feature a dynamic random magic item generator.
- Raised cumulative_weighted_choice function to top level.
- Added test for cumulative_weighted_choice as free function.
- Updated MultiCat documentation for clarity.
Fortuna 0.16.0
- Pushed distribution_timer to the .pyx layer.
- Changed default number of iterations of tests to 1 million, up form 1 hundred thousand.
- Reordered tests to better match documentation.
- Added Base Case Fortuna.fast_rand_below.
- Added Base Case Fortuna.fast_d.
- Added Base Case Fortuna.fast_dice.
Fortuna 0.15.10
- Internal Development Cycle
Fortuna 0.15.9
- Added Base Cases for random_value()
- Added Base Case for randint()
Fortuna 0.15.8
- Clarified MultiCat Test
Fortuna 0.15.7
- Fixed minor typos.
Fortuna 0.15.6
- Fixed minor typos.
- Simplified MultiCat example.
Fortuna 0.15.5
- Added MultiCat test.
- Fixed some minor typos in docs.
Fortuna 0.15.4
- Performance optimization for both WeightedChoice() variants.
- Cython update provides small performance enhancement across the board.
- Compilation now leverages Python3 all the way down.
- MultiCat pushed to the .pyx layer for better performance.
Fortuna 0.15.3
- Reworked the MultiCat example to include several randomizing strategies working in concert.
- Added Multi Dice 10d10 performance tests.
- Updated sudo code in documentation to be more pythonic.
Fortuna 0.15.2
- Fixed: Linux installation failure.
- Added: complete source files to the distribution (.cpp .hpp .pyx).
Fortuna 0.15.1
- Updated & simplified distribution_timer in
fortuna_tests.py
- Readme updated, fixed some typos.
- Known issue preventing successful installation on some linux platforms.
Fortuna 0.15.0
- Performance tweaks.
- Readme updated, added some details.
Fortuna 0.14.1
- Readme updated, fixed some typos.
Fortuna 0.14.0
- Fixed a bug where the analytic continuation algorithm caused a rare issue during compilation on some platforms.
Fortuna 0.13.3
- Fixed Test Bug: percent sign was missing in output distributions.
- Readme updated: added update history, fixed some typos.
Fortuna 0.13.2
- Readme updated for even more clarity.
Fortuna 0.13.1
- Readme updated for clarity.
Fortuna 0.13.0
- Minor Bug Fixes.
- Readme updated for aesthetics.
- Added Tests:
.../fortuna_extras/fortuna_tests.py
Fortuna 0.12.0
- Internal test for future update.
Fortuna 0.11.0
- Initial Release: Public Beta
Fortuna 0.10.0
- Module name changed from Dice to Fortuna
Dice 0.1.x - 0.9.x
- Experimental Phase
Distribution and Performance Tests
Testbed:
- Hardware: 2.7Ghz Quad i7 Skylake, 16GB RAM, 1TB SSD
- Software: MacOS 10.14.6, Python 3.8, MonkeyScope: Fortuna
MonkeyScope: Fortuna Quick Test
Random Sequence Values:
some_list = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9]
Base Case
Output Analysis: Random.choice(some_list)
Typical Timing: 490 ± 29 ns
Statistics of 1000 samples:
Minimum: 0
Median: 5
Maximum: 9
Mean: 4.614
Std Deviation: 2.960237152661928
Distribution of 100000 samples:
0: 10.003%
1: 10.07%
2: 9.943%
3: 9.99%
4: 9.913%
5: 9.922%
6: 9.894%
7: 9.991%
8: 9.957%
9: 10.317%
Output Analysis: random_value(some_list)
Typical Timing: 71 ± 6 ns
Statistics of 1000 samples:
Minimum: 0
Median: 5
Maximum: 9
Mean: 4.602
Std Deviation: 2.8407034340106674
Distribution of 100000 samples:
0: 9.94%
1: 10.127%
2: 10.136%
3: 10.137%
4: 9.954%
5: 9.907%
6: 9.939%
7: 10.107%
8: 9.879%
9: 9.874%
Wide Distribution
truffle = TruffleShuffle(some_list)
Output Analysis: truffle()
Typical Timing: 494 ± 21 ns
Statistics of 1000 samples:
Minimum: 0
Median: 5
Maximum: 9
Mean: 4.545
Std Deviation: 2.831602902950906
Distribution of 100000 samples:
0: 10.094%
1: 10.047%
2: 9.928%
3: 9.96%
4: 9.993%
5: 10.076%
6: 9.95%
7: 9.93%
8: 9.964%
9: 10.058%
Single objects with many distribution possibilities
some_tuple = tuple(i for i in range(10))
monty = QuantumMonty(some_tuple)
Output Analysis: monty()
Typical Timing: 518 ± 34 ns
Statistics of 1000 samples:
Minimum: 0
Median: 5
Maximum: 9
Mean: 4.572
Std Deviation: 2.8595132452919327
Distribution of 100000 samples:
0: 10.813%
1: 8.856%
2: 9.059%
3: 9.762%
4: 11.51%
5: 11.752%
6: 9.51%
7: 9.006%
8: 8.934%
9: 10.798%
rand_value = RandomValue(collection, zero_cool=random_index)
Output Analysis: rand_value()
Typical Timing: 406 ± 12 ns
Statistics of 1000 samples:
Minimum: 0
Median: 5
Maximum: 9
Mean: 4.582
Std Deviation: 2.8300664303157266
Distribution of 100000 samples:
0: 9.862%
1: 10.043%
2: 9.879%
3: 10.038%
4: 9.953%
5: 10.035%
6: 10.061%
7: 9.942%
8: 10.116%
9: 10.071%
Weighted Tables:
population = ('A', 'B', 'C', 'D')
cum_weights = (1, 3, 6, 10)
rel_weights = (1, 2, 3, 4)
cum_weighted_table = zip(cum_weights, population)
rel_weighted_table = zip(rel_weights, population)
Cumulative Base Case
Output Analysis: Random.choices(population, cum_weights=cum_weights)
Typical Timing: 1467 ± 66 ns
Distribution of 100000 samples:
A: 9.933%
B: 19.846%
C: 30.24%
D: 39.981%
cum_weighted_choice = CumulativeWeightedChoice(cum_weighted_table)
Output Analysis: cum_weighted_choice()
Typical Timing: 411 ± 29 ns
Distribution of 100000 samples:
A: 10.022%
B: 20.053%
C: 29.883%
D: 40.042%
Output Analysis: cumulative_weighted_choice(tuple(zip(cum_weights, population)))
Typical Timing: 141 ± 2 ns
Distribution of 100000 samples:
A: 9.936%
B: 20.007%
C: 29.735%
D: 40.322%
Relative Base Case
Output Analysis: Random.choices(population, weights=rel_weights)
Typical Timing: 1878 ± 75 ns
Distribution of 100000 samples:
A: 9.919%
B: 20.06%
C: 29.994%
D: 40.027%
rel_weighted_choice = RelativeWeightedChoice(rel_weighted_table)
Output Analysis: rel_weighted_choice()
Typical Timing: 386 ± 19 ns
Distribution of 100000 samples:
A: 9.899%
B: 20.051%
C: 29.919%
D: 40.131%
Random Matrix Values:
some_matrix = {'A': (1, 2, 3, 4), 'B': (10, 20, 30, 40), 'C': (100, 200, 300, 400)}
flex_cat = FlexCat(some_matrix)
Output Analysis: flex_cat()
Typical Timing: 886 ± 36 ns
Statistics of 1000 samples:
Minimum: 1
Median: 4
Maximum: 400
Mean: 38.262
Std Deviation: 85.84867707775118
Distribution of 100000 samples:
1: 13.841%
2: 13.883%
3: 13.892%
4: 13.933%
10: 8.36%
20: 8.384%
30: 8.21%
40: 8.403%
100: 2.751%
200: 2.756%
300: 2.806%
400: 2.781%
Output Analysis: flex_cat("C")
Typical Timing: 635 ± 58 ns
Statistics of 1000 samples:
Minimum: 100
Median: 200
Maximum: 400
Mean: 249.7
Std Deviation: 111.71351753480863
Distribution of 100000 samples:
100: 24.955%
200: 24.813%
300: 25.105%
400: 25.127%
Random Integers:
Base Case
Output Analysis: Random.randrange(10)
Typical Timing: 554 ± 16 ns
Statistics of 1000 samples:
Minimum: 0
Median: 5
Maximum: 9
Mean: 4.589
Std Deviation: 2.8823738480634327
Distribution of 100000 samples:
0: 9.956%
1: 10.029%
2: 9.97%
3: 9.971%
4: 10.039%
5: 9.847%
6: 10.027%
7: 9.883%
8: 10.202%
9: 10.076%
Output Analysis: random_below(10)
Typical Timing: 78 ± 13 ns
Statistics of 1000 samples:
Minimum: 0
Median: 4
Maximum: 9
Mean: 4.459
Std Deviation: 2.8671098688400485
Distribution of 100000 samples:
0: 10.019%
1: 9.971%
2: 9.959%
3: 10.011%
4: 10.234%
5: 9.973%
6: 9.78%
7: 10.02%
8: 10.116%
9: 9.917%
Output Analysis: random_index(10)
Typical Timing: 81 ± 15 ns
Statistics of 1000 samples:
Minimum: 0
Median: 4
Maximum: 9
Mean: 4.433
Std Deviation: 2.8704548420067506
Distribution of 100000 samples:
0: 9.858%
1: 9.883%
2: 10.166%
3: 10.059%
4: 10.166%
5: 10.115%
6: 9.958%
7: 9.953%
8: 9.904%
9: 9.938%
Output Analysis: random_range(10)
Typical Timing: 85 ± 7 ns
Statistics of 1000 samples:
Minimum: 0
Median: 4
Maximum: 9
Mean: 4.435
Std Deviation: 2.8435497182219267
Distribution of 100000 samples:
0: 10.073%
1: 9.939%
2: 10.093%
3: 9.743%
4: 10.047%
5: 10.121%
6: 10.051%
7: 9.975%
8: 9.969%
9: 9.989%
Output Analysis: random_below(-10)
Typical Timing: 75 ± 2 ns
Statistics of 1000 samples:
Minimum: -9
Median: -4
Maximum: 0
Mean: -4.386
Std Deviation: 2.908092845835566
Distribution of 100000 samples:
-9: 10.052%
-8: 9.928%
-7: 10.062%
-6: 10.202%
-5: 9.938%
-4: 9.874%
-3: 9.958%
-2: 10.028%
-1: 10.029%
0: 9.929%
Output Analysis: random_index(-10)
Typical Timing: 88 ± 11 ns
Statistics of 1000 samples:
Minimum: -10
Median: -5
Maximum: -1
Mean: -5.463
Std Deviation: 2.9142119003257125
Distribution of 100000 samples:
-10: 10.104%
-9: 9.959%
-8: 10.112%
-7: 10.034%
-6: 9.989%
-5: 10.064%
-4: 9.769%
-3: 9.967%
-2: 9.896%
-1: 10.106%
Output Analysis: random_range(-10)
Typical Timing: 97 ± 8 ns
Statistics of 1000 samples:
Minimum: -10
Median: (-6, -5)
Maximum: -1
Mean: -5.476
Std Deviation: 2.861018000642429
Distribution of 100000 samples:
-10: 9.954%
-9: 9.944%
-8: 9.836%
-7: 10.091%
-6: 9.977%
-5: 10.116%
-4: 10.033%
-3: 9.978%
-2: 10.056%
-1: 10.015%
Base Case
Output Analysis: Random.randrange(1, 10)
Typical Timing: 757 ± 66 ns
Statistics of 1000 samples:
Minimum: 1
Median: 5
Maximum: 9
Mean: 5.045
Std Deviation: 2.6628884693129753
Distribution of 100000 samples:
1: 11.142%
2: 10.995%
3: 11.105%
4: 10.953%
5: 11.19%
6: 11.239%
7: 11.074%
8: 11.226%
9: 11.076%
Output Analysis: random_range(1, 10)
Typical Timing: 92 ± 7 ns
Statistics of 1000 samples:
Minimum: 1
Median: 5
Maximum: 9
Mean: 5.044
Std Deviation: 2.642359551612914
Distribution of 100000 samples:
1: 10.996%
2: 10.987%
3: 11.095%
4: 11.161%
5: 11.118%
6: 11.042%
7: 11.084%
8: 11.142%
9: 11.375%
Output Analysis: random_range(10, 1)
Typical Timing: 90 ± 8 ns
Statistics of 1000 samples:
Minimum: 1
Median: 5
Maximum: 9
Mean: 5.189
Std Deviation: 2.622837966783308
Distribution of 100000 samples:
1: 10.963%
2: 11.176%
3: 10.977%
4: 11.168%
5: 11.123%
6: 10.893%
7: 11.369%
8: 11.119%
9: 11.212%
Base Case
Output Analysis: Random.randint(-5, 5)
Typical Timing: 871 ± 43 ns
Statistics of 1000 samples:
Minimum: -5
Median: 0
Maximum: 5
Mean: 0.127
Std Deviation: 3.1446575330232704
Distribution of 100000 samples:
-5: 8.99%
-4: 9.088%
-3: 8.964%
-2: 9.051%
-1: 9.023%
0: 9.091%
1: 9.052%
2: 9.182%
3: 9.264%
4: 9.182%
5: 9.113%
Output Analysis: random_int(-5, 5)
Typical Timing: 66 ± 8 ns
Statistics of 1000 samples:
Minimum: -5
Median: 0
Maximum: 5
Mean: -0.002
Std Deviation: 3.200936737894081
Distribution of 100000 samples:
-5: 9.195%
-4: 8.938%
-3: 9.142%
-2: 9.04%
-1: 8.927%
0: 9.189%
1: 9.266%
2: 9.05%
3: 8.951%
4: 9.117%
5: 9.185%
Base Case
Output Analysis: Random.randrange(1, 20, 2)
Typical Timing: 970 ± 51 ns
Statistics of 1000 samples:
Minimum: 1
Median: 11
Maximum: 19
Mean: 10.156
Std Deviation: 5.779936331829271
Distribution of 100000 samples:
1: 9.947%
3: 9.854%
5: 10.024%
7: 9.951%
9: 10.007%
11: 10.173%
13: 10.015%
15: 9.929%
17: 10.131%
19: 9.969%
Output Analysis: random_range(1, 20, 2)
Typical Timing: 85 ± 3 ns
Statistics of 1000 samples:
Minimum: 1
Median: 11
Maximum: 19
Mean: 10.062
Std Deviation: 5.816197727037828
Distribution of 100000 samples:
1: 9.943%
3: 10.11%
5: 9.878%
7: 10.055%
9: 10.041%
11: 9.906%
13: 10.056%
15: 10.069%
17: 9.999%
19: 9.943%
Output Analysis: random_range(1, 20, -2)
Typical Timing: 96 ± 11 ns
Statistics of 1000 samples:
Minimum: 2
Median: 12
Maximum: 20
Mean: 10.994
Std Deviation: 5.718737972664948
Distribution of 100000 samples:
2: 9.953%
4: 9.893%
6: 9.91%
8: 9.934%
10: 10.016%
12: 10.054%
14: 10.092%
16: 10.106%
18: 10.077%
20: 9.965%
Output Analysis: random_range(20, 1, -2)
Typical Timing: 96 ± 11 ns
Statistics of 1000 samples:
Minimum: 2
Median: 10
Maximum: 20
Mean: 10.842
Std Deviation: 5.795777428438742
Distribution of 100000 samples:
2: 10.189%
4: 10.1%
6: 10.008%
8: 9.984%
10: 10.077%
12: 9.842%
14: 10.093%
16: 9.789%
18: 9.882%
20: 10.036%
Output Analysis: d(10)
Typical Timing: 60 ± 2 ns
Statistics of 1000 samples:
Minimum: 1
Median: 6
Maximum: 10
Mean: 5.647
Std Deviation: 2.811830542546972
Distribution of 100000 samples:
1: 9.959%
2: 10.054%
3: 9.857%
4: 10.031%
5: 9.964%
6: 9.874%
7: 9.898%
8: 10.155%
9: 10.159%
10: 10.049%
Output Analysis: dice(3, 6)
Typical Timing: 111 ± 9 ns
Statistics of 1000 samples:
Minimum: 3
Median: 11
Maximum: 18
Mean: 10.544
Std Deviation: 2.841841656391151
Distribution of 100000 samples:
3: 0.464%
4: 1.368%
5: 2.793%
6: 4.605%
7: 6.925%
8: 9.662%
9: 11.578%
10: 12.404%
11: 12.684%
12: 11.539%
13: 9.907%
14: 6.989%
15: 4.494%
16: 2.7%
17: 1.437%
18: 0.451%
Output Analysis: ability_dice(4)
Typical Timing: 201 ± 10 ns
Statistics of 1000 samples:
Minimum: 3
Median: 12
Maximum: 18
Mean: 12.189
Std Deviation: 2.938584523201604
Distribution of 100000 samples:
3: 0.086%
4: 0.303%
5: 0.778%
6: 1.619%
7: 2.972%
8: 4.768%
9: 6.858%
10: 9.522%
11: 11.463%
12: 12.929%
13: 13.345%
14: 12.183%
15: 10.077%
16: 7.272%
17: 4.171%
18: 1.654%
Output Analysis: plus_or_minus(5)
Typical Timing: 52 ± 2 ns
Statistics of 1000 samples:
Minimum: -5
Median: 0
Maximum: 5
Mean: 0.047
Std Deviation: 3.1478232161288853
Distribution of 100000 samples:
-5: 9.167%
-4: 9.181%
-3: 9.221%
-2: 9.1%
-1: 9.059%
0: 8.946%
1: 9.118%
2: 9.206%
3: 9.022%
4: 9.054%
5: 8.926%
Output Analysis: plus_or_minus_linear(5)
Typical Timing: 91 ± 18 ns
Statistics of 1000 samples:
Minimum: -5
Median: 0
Maximum: 5
Mean: -0.116
Std Deviation: 2.451641083029896
Distribution of 100000 samples:
-5: 2.759%
-4: 5.612%
-3: 8.345%
-2: 11.031%
-1: 14.033%
0: 16.658%
1: 13.688%
2: 11.209%
3: 8.323%
4: 5.506%
5: 2.836%
Output Analysis: plus_or_minus_gauss(5)
Typical Timing: 111 ± 18 ns
Statistics of 1000 samples:
Minimum: -5
Median: 0
Maximum: 5
Mean: -0.101
Std Deviation: 1.55524885468532
Distribution of 100000 samples:
-5: 0.223%
-4: 1.147%
-3: 4.371%
-2: 11.525%
-1: 20.594%
0: 24.382%
1: 20.345%
2: 11.556%
3: 4.455%
4: 1.188%
5: 0.214%
Random Floats:
Base Case
Output Analysis: Random.random()
Typical Timing: 40 ± 2 ns
Statistics of 1000 samples:
Minimum: 0.0007654983001164073
Median: (0.5054512007718543, 0.5067034440401829)
Maximum: 0.9982570973801891
Mean: 0.5074441134775397
Std Deviation: 0.29203536128224095
Post-processor distribution of 100000 samples using round method:
0: 50.075%
1: 49.925%
Output Analysis: canonical()
Typical Timing: 54 ± 9 ns
Statistics of 1000 samples:
Minimum: 0.0014180131310916966
Median: (0.5363437884584212, 0.5371522269085013)
Maximum: 0.9992614997904025
Mean: 0.5098676988927412
Std Deviation: 0.2832571190559935
Post-processor distribution of 100000 samples using round method:
0: 50.041%
1: 49.959%
Output Analysis: random_float(0.0, 10.0)
Typical Timing: 45 ± 2 ns
Statistics of 1000 samples:
Minimum: 0.0048328230274767405
Median: (4.965188968057807, 4.971365297458431)
Maximum: 9.984653509054702
Mean: 5.074860564623359
Std Deviation: 2.958057011585399
Post-processor distribution of 100000 samples using floor method:
0: 10.025%
1: 10.116%
2: 10.015%
3: 9.919%
4: 9.902%
5: 9.903%
6: 10.092%
7: 9.993%
8: 9.92%
9: 10.115%
Base Case
Output Analysis: Random.triangular(0.0, 10.0, 5.0)
Typical Timing: 495 ± 39 ns
Statistics of 1000 samples:
Minimum: 0.24334419892073916
Median: (4.979669241307796, 4.9796919795601795)
Maximum: 9.905635230254449
Mean: 5.048555919078824
Std Deviation: 2.0144049584692234
Post-processor distribution of 100000 samples using round method:
0: 0.485%
1: 3.971%
2: 8.033%
3: 11.854%
4: 16.008%
5: 18.935%
6: 16.061%
7: 12.04%
8: 8.037%
9: 4.087%
10: 0.489%
Output Analysis: triangular(0.0, 10.0, 5.0)
Typical Timing: 63 ± 5 ns
Statistics of 1000 samples:
Minimum: 0.4895261373969887
Median: (5.08650975656024, 5.089694023314037)
Maximum: 9.530085426296651
Mean: 5.074886148391277
Std Deviation: 1.9960583868019923
Post-processor distribution of 100000 samples using round method:
0: 0.524%
1: 4.048%
2: 7.847%
3: 11.869%
4: 16.115%
5: 19.045%
6: 16.155%
7: 11.959%
8: 7.925%
9: 4.006%
10: 0.507%
Random Booleans:
Output Analysis: percent_true(33.33)
Typical Timing: 41 ± 2 ns
Statistics of 1000 samples:
Minimum: False
Median: False
Maximum: True
Mean: 0.322
Std Deviation: 0.4672429774753174
Distribution of 100000 samples:
False: 66.551%
True: 33.449%
Shuffle Performance:
some_small_list = [i for i in range(10)]
some_med_list = [i for i in range(100)]
some_large_list = [i for i in range(1000)]
Base Case:
Random.shuffle()
Typical Timing: 4502 ± 244 ns
Typical Timing: 39869 ± 155 ns
Typical Timing: 440912 ± 1915 ns
Fortuna.shuffle()
Typical Timing: 305 ± 33 ns
Typical Timing: 3178 ± 45 ns
Typical Timing: 30771 ± 117 ns
Fortuna.knuth_a()
Typical Timing: 923 ± 38 ns
Typical Timing: 7171 ± 52 ns
Typical Timing: 90639 ± 1368 ns
Fortuna.fisher_yates()
Typical Timing: 1037 ± 49 ns
Typical Timing: 7347 ± 58 ns
Typical Timing: 94037 ± 4052 ns
-------------------------------------------------------------------------
Total Test Time: 3.114 seconds
Legal Information
Fortuna © 2019 Robert W Sharp, all rights reserved.
Fortuna is licensed under a Creative Commons Attribution-NonCommercial 3.0 Unported License.
See online version of this license here: http://creativecommons.org/licenses/by-nc/3.0/
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
File details
Details for the file Fortuna-3.14.0.tar.gz
.
File metadata
- Download URL: Fortuna-3.14.0.tar.gz
- Upload date:
- Size: 182.7 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.1.1 pkginfo/1.5.0.1 requests/2.22.0 setuptools/42.0.2 requests-toolbelt/0.9.1 tqdm/4.40.2 CPython/3.8.0
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 587436c84eadc7a800baa5e4718c576247f9afd14a229471f4bed9d61b17868c |
|
MD5 | 427addfd4e072cf7b90b1e028ef79e1c |
|
BLAKE2b-256 | dcf0a5bd055124e2a919cd2fb0d192b4e18db6a5ce87fc7452b19edcf8ca9f12 |
Provenance
File details
Details for the file Fortuna-3.14.0-cp38-cp38-macosx_10_9_x86_64.whl
.
File metadata
- Download URL: Fortuna-3.14.0-cp38-cp38-macosx_10_9_x86_64.whl
- Upload date:
- Size: 159.4 kB
- Tags: CPython 3.8, macOS 10.9+ x86-64
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.1.1 pkginfo/1.5.0.1 requests/2.22.0 setuptools/42.0.2 requests-toolbelt/0.9.1 tqdm/4.40.2 CPython/3.8.0
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | b08e77719499cfb21dbb7f8f574905d90dcd5a0322bdb3fe631c05e8f81c5d80 |
|
MD5 | 52cd4c67366e880695acfd39ca485963 |
|
BLAKE2b-256 | 4e5da99aa4e7863ed2244e7723c3561951ff55a60afeb1eb6f447d86f97ffa42 |