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 generators for your data.
The core functionality of Fortuna is based on the Storm RNG Engine. While Storm is a high quality random engine, Fortuna is not appropriate for cryptography of any kind. Fortuna is meant for games, data science, A.I. and experimental programming, not security.
Suggested Installation: $ pip install Fortuna
Precompiled for MacOS, installation on other platforms may require building from source.
Sister Projects:
- 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 generators. https://pypi.org/project/MonkeyScope/
Support these and other random projects: https://www.patreon.com/brokencode
Table of Contents:
- Numeric Limits
- Project Terminology
- Random Generators:
- 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_geometric(Integer) -> Integer
middle_geometric(Integer) -> Integer
back_geometric(Integer) -> Integer
quantum_geometric(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
shuffle(List) -> None
- 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-324
Project Terminology:
- Value: Almost anything in Python can be a Value.
- Expressions, Generators, and F-strings should be wrapped in a lambda for dynamic evaluation.
- Callable: Any callable object, function, method or lambda.
- Collection: A group of Values.
- List, Tuple, Set, etc... Any object that can be converted into a list via
list(some_object)
. - Comprehensions that produce a Collection also qualify.
- Fortuna classes that wrap a Collection can wrap a Collection, Sequence or generator.
- Fortuna functions that take a Collection as input will always require a Sequence.
- List, Tuple, Set, etc... Any object that can be converted into a list via
- Sequence: An ordered Collection.
- List, tuple or list comprehension.
- A Sequence is an ordered Collection that can be indexed like a list, without conversion.
- All Sequences are Collections but not all Collections are Sequences.
- 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
- Exclusive Range.
(0, 11) -> 1, 2, 3, 4, 5, 6, 7, 8, 9, 10
- Partially Exclusive Range.
[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.
- Mixing callable objects with un-callable objects is fully supported, but it can look a bit messy.
- Nested callable objects are fully supported. Because
lambda(lambda) -> lambda
fixes everything for arbitrary values of 'because', 'fixes' and 'everything'. - To disable automatic flattening, pass the optional keyword argument
flat=False
to the constructor. - Under development: It will soon be possible to auto-flatten callable objects that require multiple arguments. RandomValue already supports this feature.
Random Value Generators
Fortuna.RandomValue
Fortuna.RandomValue(data: Collection, flat=True) -> Callable -> Value
- @param data :: Collection of Values.
- @param flat :: Bool. Default: True. Option to automatically flatten callable values with lazy evaluation.
- @return :: Callable Object.
Callable(*args, zero_cool=random_index, range_to=0, **kwargs) -> Value
- @param zero_cool :: Optional ZeroCool Method, kwarg only. Default = random_index().
- @param range_to :: Optional Integer in range [-N, N] where N is the length of the Collection.
- Default = 0, kwarg only. Parameter for ZeroCool Method.
- Negative values of range_to indicate ranging from the back of the Collection.
- @param *args, **kwargs :: Optional arguments used to flatten the return Value.
- @return Value or Value(*args, **kwargs) if it's Callable.
from Fortuna import RandomValue, front_linear, back_linear
# Data Setup
random_apple = RandomValue(("Delicious", "Empire", "Granny Smith", "Honey Crisp", "Macintosh"))
random_fruit = RandomValue((
lambda: f"Apple, {random_apple()}",
"Banana",
"Cherry",
"Grapes",
"Orange",
))
# Usage
print(random_fruit())
# prints a random fruit with the default flat uniform distribution
print(random_fruit(zero_cool=back_linear))
# prints a random fruit with a back_linear distribution
print(random_fruit(range_to=3))
# prints a random fruit of the first 3
print(random_fruit(zero_cool=front_linear, range_to=-3))
# prints a random fruit of the last 3 with a front_linear distribution of that range.
TruffleShuffle
Fortuna.TruffleShuffle(data: Collection, flat=True) -> Callable -> Value
- Non-destructive, copies the data once.
- @param data :: Collection of Values. Set recommended but not required.
- @param flat :: Bool. Default: True. Option to automatically flatten callable values with lazy evaluation.
- @return :: Callable
- @return :: Random value from the list with a Wide Uniform Distribution. The average width of the output distribution will naturally scale up with the size of the set.
Wide Uniform Distribution: "Wide" refers to the average distance between consecutive occurrences of the same value in the output sequence. 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,
# over time it will produce a wide distribution.
RandomValue with Auto Flattening Callable Objects
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 still recommended to specify flat=False if non-flat output is intend.
print(auto_un_flat()(1)) # will print the value 1, 2 or 3, mind the double-double parenthesis
Mixing Static Objects with Callable Objects
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_un_flat = RandomValue([1, 2, lambda: 3], flat=False) # this pattern 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, at least one level of indirection is required. Without an indirection the f-string would collapse into a static string too soon.
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, flattened at call time.
"""
>>> distribution_timer(dynamic_string)
Output Analysis: RandomValue(collection)()
Typical Timing: 875 ± 15 ns
Distribution of 100000 Samples:
A1: 16.657%
A2: 16.777%
B1: 8.408%
B2: 8.266%
B3: 8.334%
B4: 8.203%
C1: 5.635%
C2: 5.641%
C3: 5.468%
C4: 5.537%
C5: 5.528%
C6: 5.546%
"""
Nesting Dolls
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
QuantumMonty
Fortuna.QuantumMonty(data: Collection, flat=True) -> Callable -> Value
- @param data :: Collection of Values.
- @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.
- @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.
- @param flat :: Bool. Default: True. Option to automatically flatten callable values with lazy evaluation.
- @return :: Callable Instance
- @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.
- @param flat :: Bool. Default: True. Option to automatically flatten callable values with lazy evaluation.
- @return :: Callable Instance
- @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(dict_of_lists: Matrix, key_bias="front_linear", val_bias="truffle_shuffle", flat=True) -> Callable -> Value
- @param dict_of_lists :: Keyed Matrix of Value Sequences.
- @parm key_bias :: String indicating the name of the algorithm to use for random key selection.
- @parm val_bias :: String indicating the name of the algorithm to use for random value selection.
- @param flat :: Bool. Default: 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.
- @return :: Value. Returns a random value generated with val_bias from a random sequence generated with key_bias.
FlexCat is like a two dimensional QuantumMonty, or a QuantumMonty of QuantumMontys.
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
"Cat_B": ("B1", "B2", "B3", "B4", "B5"), # $
"Cat_C": ("C1", "C2", "C3", f"C4.{d(2)}", lambda: f"C5.{d(4)}"),
}# $ $ $ $ $
# | | |- Value | |- Fair die method
# | | |
# | |- 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]
a 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 :: Any Integer. 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 of multiple rolls of the same size die.
- @param rolls :: Any Integer. Represents the number of times to roll the die.
- @param sides :: Any Integer. 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 :: Any Integer.
- @return :: Returns a random integer in range [-number, number].
- Flat uniform distribution.
Fortuna.plus_or_minus_linear(number: int) -> int
- @param number :: Any Integer.
- @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 :: Any Integer.
- @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.
- 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 index values or from the front for positive index values.
from Fortuna import random_index
some_list = [i for i in range(100)]
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: Twelve-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
- @param b :: Float
- @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.
- Always returns False if num is 0 or less
- Always returns True if num is 100 or more.
Shuffle Algorithms
Fortuna.shuffle(array: list) -> None
- Knuth B shuffle algorithm. Destructive, in-place shuffle.
- @param array :: Must be a mutable list-like object.
Fortuna Development Log
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
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: 782 ± 27 ns
Statistics of 1024 samples:
Minimum: 0
Median: 5
Maximum: 9
Mean: 4.4599609375
Std Deviation: 2.9035250760903266
Distribution of 102400 samples:
0: 9.955078125%
1: 9.8935546875%
2: 9.958984375%
3: 10.1376953125%
4: 10.037109375%
5: 10.0166015625%
6: 10.1572265625%
7: 9.904296875%
8: 9.9267578125%
9: 10.0126953125%
Output Analysis: random_value(some_list)
Typical Timing: 63 ± 12 ns
Statistics of 1024 samples:
Minimum: 0
Median: 4
Maximum: 9
Mean: 4.53515625
Std Deviation: 2.862562881618829
Distribution of 102400 samples:
0: 10.103515625%
1: 9.888671875%
2: 9.994140625%
3: 10.0087890625%
4: 10.08984375%
5: 9.939453125%
6: 9.9384765625%
7: 10.1572265625%
8: 10.0205078125%
9: 9.859375%
Output Analysis: TruffleShuffle(collection)()
Typical Timing: 500 ± 10 ns
Statistics of 1024 samples:
Minimum: 0
Median: 4
Maximum: 9
Mean: 4.41015625
Std Deviation: 2.853841775359643
Distribution of 102400 samples:
0: 9.998046875%
1: 10.0458984375%
2: 10.0029296875%
3: 9.935546875%
4: 10.0625%
5: 9.9990234375%
6: 9.9970703125%
7: 9.9599609375%
8: 9.98046875%
9: 10.0185546875%
Output Analysis: QuantumMonty(collection)()
Typical Timing: 500 ± 14 ns
Statistics of 1024 samples:
Minimum: 0
Median: 4
Maximum: 9
Mean: 4.4921875
Std Deviation: 2.843238536659224
Distribution of 102400 samples:
0: 10.9453125%
1: 8.822265625%
2: 8.9599609375%
3: 9.72265625%
4: 11.6435546875%
5: 11.341796875%
6: 9.697265625%
7: 9.126953125%
8: 8.8837890625%
9: 10.8564453125%
Output Analysis: RandomValue(collection)()
Typical Timing: 407 ± 11 ns
Statistics of 1024 samples:
Minimum: 0
Median: 4
Maximum: 9
Mean: 4.603515625
Std Deviation: 2.783316330995652
Distribution of 102400 samples:
0: 9.9072265625%
1: 9.951171875%
2: 10.0859375%
3: 9.9482421875%
4: 10.2236328125%
5: 9.806640625%
6: 10.0009765625%
7: 10.015625%
8: 10.134765625%
9: 9.92578125%
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: 2000 ± 14 ns
Distribution of 102400 samples:
A: 10.0302734375%
B: 20.064453125%
C: 30.068359375%
D: 39.8369140625%
Output Analysis: CumulativeWeightedChoice(weighted_table)()
Typical Timing: 407 ± 8 ns
Distribution of 102400 samples:
A: 9.9443359375%
B: 20.0625%
C: 30.2900390625%
D: 39.703125%
Output Analysis: cumulative_weighted_choice(tuple(zip(cum_weights, population)))
Typical Timing: 125 ± 14 ns
Distribution of 102400 samples:
A: 9.9580078125%
B: 20.0341796875%
C: 29.931640625%
D: 40.076171875%
Relative Base Case
Output Analysis: Random.choices(population, weights=rel_weights)
Typical Timing: 2094 ± 20 ns
Distribution of 102400 samples:
A: 9.9765625%
B: 19.873046875%
C: 30.20703125%
D: 39.943359375%
Output Analysis: RelativeWeightedChoice(weighted_table)()
Typical Timing: 407 ± 11 ns
Distribution of 102400 samples:
A: 9.97265625%
B: 20.0703125%
C: 29.9453125%
D: 40.01171875%
Random Matrix Values:
some_matrix = {'A': (1, 2, 3, 4), 'B': (10, 20, 30, 40), 'C': (100, 200, 300, 400)}
Output Analysis: FlexCat(matrix_data, key_bias, val_bias, flat)()
Typical Timing: 782 ± 6 ns
Statistics of 1024 samples:
Minimum: 1
Median: 20
Maximum: 400
Mean: 89.935546875
Std Deviation: 127.22256629419442
Distribution of 102400 samples:
1: 8.30859375%
2: 8.3369140625%
3: 8.44140625%
4: 8.4130859375%
10: 8.3466796875%
20: 8.3173828125%
30: 8.34375%
40: 8.3115234375%
100: 8.251953125%
200: 8.3037109375%
300: 8.16015625%
400: 8.46484375%
Random Integers:
Base Case
Output Analysis: Random.randrange(10)
Typical Timing: 813 ± 25 ns
Statistics of 1024 samples:
Minimum: 0
Median: 4
Maximum: 9
Mean: 4.51953125
Std Deviation: 2.868170519006795
Distribution of 102400 samples:
0: 10.0869140625%
1: 10.091796875%
2: 9.958984375%
3: 10.0166015625%
4: 9.9794921875%
5: 9.947265625%
6: 9.98046875%
7: 10.107421875%
8: 9.869140625%
9: 9.9619140625%
Output Analysis: random_below(10)
Typical Timing: 63 ± 1 ns
Statistics of 1024 samples:
Minimum: 0
Median: 4
Maximum: 9
Mean: 4.37890625
Std Deviation: 2.9230911300613274
Distribution of 102400 samples:
0: 10.14453125%
1: 9.9638671875%
2: 10.0185546875%
3: 9.9677734375%
4: 9.802734375%
5: 9.9521484375%
6: 9.9453125%
7: 10.0751953125%
8: 10.0166015625%
9: 10.11328125%
Output Analysis: random_index(10)
Typical Timing: 63 ± 10 ns
Statistics of 1024 samples:
Minimum: 0
Median: 5
Maximum: 9
Mean: 4.5625
Std Deviation: 2.8777638761173954
Distribution of 102400 samples:
0: 10.189453125%
1: 9.923828125%
2: 9.9072265625%
3: 10.0888671875%
4: 9.9130859375%
5: 10.013671875%
6: 9.9755859375%
7: 10.1025390625%
8: 9.9169921875%
9: 9.96875%
Output Analysis: random_range(10)
Typical Timing: 63 ± 10 ns
Statistics of 1024 samples:
Minimum: 0
Median: 5
Maximum: 9
Mean: 4.546875
Std Deviation: 2.9067874861668286
Distribution of 102400 samples:
0: 10.1337890625%
1: 10.228515625%
2: 9.8857421875%
3: 9.9951171875%
4: 9.99609375%
5: 9.9521484375%
6: 9.935546875%
7: 9.853515625%
8: 10.001953125%
9: 10.017578125%
Output Analysis: random_below(-10)
Typical Timing: 63 ± 16 ns
Statistics of 1024 samples:
Minimum: -9
Median: -4
Maximum: 0
Mean: -4.451171875
Std Deviation: 2.831804876747456
Distribution of 102400 samples:
-9: 9.9306640625%
-8: 9.9111328125%
-7: 10.2060546875%
-6: 9.9287109375%
-5: 10.1142578125%
-4: 9.8017578125%
-3: 9.91015625%
-2: 10.0908203125%
-1: 10.126953125%
0: 9.9794921875%
Output Analysis: random_index(-10)
Typical Timing: 63 ± 13 ns
Statistics of 1024 samples:
Minimum: -10
Median: (-6, -5)
Maximum: -1
Mean: -5.552734375
Std Deviation: 2.861268020646201
Distribution of 102400 samples:
-10: 9.9423828125%
-9: 10.029296875%
-8: 9.951171875%
-7: 9.80859375%
-6: 10.1953125%
-5: 9.8173828125%
-4: 10.130859375%
-3: 10.0419921875%
-2: 9.94140625%
-1: 10.1416015625%
Output Analysis: random_range(-10)
Typical Timing: 94 ± 12 ns
Statistics of 1024 samples:
Minimum: -10
Median: -6
Maximum: -1
Mean: -5.5283203125
Std Deviation: 2.9234580133054124
Distribution of 102400 samples:
-10: 9.9140625%
-9: 10.09765625%
-8: 10.052734375%
-7: 9.9580078125%
-6: 9.853515625%
-5: 9.939453125%
-4: 10.0771484375%
-3: 10.03515625%
-2: 10.005859375%
-1: 10.06640625%
Base Case
Output Analysis: Random.randrange(1, 10)
Typical Timing: 1063 ± 23 ns
Statistics of 1024 samples:
Minimum: 1
Median: 5
Maximum: 9
Mean: 4.9111328125
Std Deviation: 2.6253358181948223
Distribution of 102400 samples:
1: 11.01953125%
2: 11.22265625%
3: 11.046875%
4: 11.1728515625%
5: 11.0517578125%
6: 11.087890625%
7: 11.14453125%
8: 11.271484375%
9: 10.982421875%
Output Analysis: random_range(1, 10)
Typical Timing: 94 ± 1 ns
Statistics of 1024 samples:
Minimum: 1
Median: 5
Maximum: 9
Mean: 4.892578125
Std Deviation: 2.486362332374238
Distribution of 102400 samples:
1: 10.9755859375%
2: 11.35546875%
3: 11.228515625%
4: 11.1025390625%
5: 11.037109375%
6: 11.201171875%
7: 11.04296875%
8: 11.1318359375%
9: 10.9248046875%
Output Analysis: random_range(10, 1)
Typical Timing: 94 ± 1 ns
Statistics of 1024 samples:
Minimum: 1
Median: 5
Maximum: 9
Mean: 4.9296875
Std Deviation: 2.6010257206742486
Distribution of 102400 samples:
1: 11.30078125%
2: 11.291015625%
3: 11.1181640625%
4: 11.0107421875%
5: 10.994140625%
6: 11.181640625%
7: 11.1943359375%
8: 10.9833984375%
9: 10.92578125%
Base Case
Output Analysis: Random.randint(-5, 5)
Typical Timing: 1157 ± 20 ns
Statistics of 1024 samples:
Minimum: -5
Median: 0
Maximum: 5
Mean: -0.166015625
Std Deviation: 3.181658294841224
Distribution of 102400 samples:
-5: 9.0458984375%
-4: 9.048828125%
-3: 8.80078125%
-2: 9.2587890625%
-1: 9.0908203125%
0: 9.0830078125%
1: 9.0126953125%
2: 8.98828125%
3: 9.140625%
4: 9.326171875%
5: 9.2041015625%
Output Analysis: random_int(-5, 5)
Typical Timing: 63 ± 11 ns
Statistics of 1024 samples:
Minimum: -5
Median: 0
Maximum: 5
Mean: -0.0634765625
Std Deviation: 3.192867482367293
Distribution of 102400 samples:
-5: 9.146484375%
-4: 9.1787109375%
-3: 9.0595703125%
-2: 9.0654296875%
-1: 9.12890625%
0: 9.044921875%
1: 9.158203125%
2: 9.0205078125%
3: 8.9345703125%
4: 9.1279296875%
5: 9.134765625%
Base Case
Output Analysis: Random.randrange(1, 20, 2)
Typical Timing: 1250 ± 26 ns
Statistics of 1024 samples:
Minimum: 1
Median: 11
Maximum: 19
Mean: 10.0703125
Std Deviation: 5.9152484084876225
Distribution of 102400 samples:
1: 10.154296875%
3: 9.8544921875%
5: 9.9736328125%
7: 9.9462890625%
9: 9.9443359375%
11: 10.1259765625%
13: 10.095703125%
15: 10.0732421875%
17: 9.9150390625%
19: 9.9169921875%
Output Analysis: random_range(1, 20, 2)
Typical Timing: 63 ± 13 ns
Statistics of 1024 samples:
Minimum: 1
Median: 11
Maximum: 19
Mean: 10.029296875
Std Deviation: 5.805508650232783
Distribution of 102400 samples:
1: 10.0888671875%
3: 9.9814453125%
5: 10.0830078125%
7: 10.0234375%
9: 9.98046875%
11: 10.0%
13: 9.92578125%
15: 9.951171875%
17: 10.0029296875%
19: 9.962890625%
Output Analysis: random_range(1, 20, -2)
Typical Timing: 94 ± 1 ns
Statistics of 1024 samples:
Minimum: 2
Median: 12
Maximum: 20
Mean: 11.19921875
Std Deviation: 5.705664158940978
Distribution of 102400 samples:
2: 9.9580078125%
4: 10.0087890625%
6: 10.1044921875%
8: 10.078125%
10: 10.05078125%
12: 10.1943359375%
14: 9.876953125%
16: 9.8974609375%
18: 9.91796875%
20: 9.9130859375%
Output Analysis: random_range(20, 1, -2)
Typical Timing: 94 ± 6 ns
Statistics of 1024 samples:
Minimum: 2
Median: (10, 12)
Maximum: 20
Mean: 10.919921875
Std Deviation: 5.8793202200594585
Distribution of 102400 samples:
2: 10.103515625%
4: 10.033203125%
6: 10.0244140625%
8: 10.0244140625%
10: 9.9833984375%
12: 9.955078125%
14: 9.8896484375%
16: 9.9404296875%
18: 10.0869140625%
20: 9.958984375%
Output Analysis: d(10)
Typical Timing: 63 ± 10 ns
Statistics of 1024 samples:
Minimum: 1
Median: 5
Maximum: 10
Mean: 5.3828125
Std Deviation: 2.8746945096738834
Distribution of 102400 samples:
1: 10.03125%
2: 10.0322265625%
3: 10.0380859375%
4: 9.9296875%
5: 9.986328125%
6: 10.0%
7: 9.9951171875%
8: 10.0498046875%
9: 9.83984375%
10: 10.09765625%
Output Analysis: dice(3, 6)
Typical Timing: 125 ± 1 ns
Statistics of 1024 samples:
Minimum: 3
Median: 10
Maximum: 18
Mean: 10.392578125
Std Deviation: 3.016115657527023
Distribution of 102400 samples:
3: 0.4921875%
4: 1.4404296875%
5: 2.7626953125%
6: 4.6435546875%
7: 6.8974609375%
8: 9.552734375%
9: 11.6748046875%
10: 12.4814453125%
11: 12.6220703125%
12: 11.5693359375%
13: 9.6650390625%
14: 6.9375%
15: 4.5869140625%
16: 2.7939453125%
17: 1.419921875%
18: 0.4599609375%
Output Analysis: ability_dice(4)
Typical Timing: 188 ± 10 ns
Statistics of 1024 samples:
Minimum: 4
Median: 12
Maximum: 18
Mean: 12.3095703125
Std Deviation: 2.8741722784745205
Distribution of 102400 samples:
3: 0.07421875%
4: 0.31640625%
5: 0.76171875%
6: 1.5810546875%
7: 2.994140625%
8: 4.806640625%
9: 7.0478515625%
10: 9.291015625%
11: 11.333984375%
12: 12.869140625%
13: 13.255859375%
14: 12.2978515625%
15: 10.140625%
16: 7.3388671875%
17: 4.3291015625%
18: 1.5615234375%
Output Analysis: plus_or_minus(5)
Typical Timing: 63 ± 6 ns
Statistics of 1024 samples:
Minimum: -5
Median: 0
Maximum: 5
Mean: -0.09375
Std Deviation: 3.1425873619468767
Distribution of 102400 samples:
-5: 8.96484375%
-4: 9.2353515625%
-3: 9.0048828125%
-2: 9.169921875%
-1: 9.1728515625%
0: 8.85546875%
1: 9.1396484375%
2: 9.001953125%
3: 9.2119140625%
4: 9.193359375%
5: 9.0498046875%
Output Analysis: plus_or_minus_linear(5)
Typical Timing: 94 ± 1 ns
Statistics of 1024 samples:
Minimum: -5
Median: 0
Maximum: 5
Mean: -0.0322265625
Std Deviation: 2.403145650198493
Distribution of 102400 samples:
-5: 2.8046875%
-4: 5.7236328125%
-3: 8.34375%
-2: 11.060546875%
-1: 14.0166015625%
0: 16.7314453125%
1: 13.8291015625%
2: 11.001953125%
3: 8.244140625%
4: 5.515625%
5: 2.728515625%
Output Analysis: plus_or_minus_gauss(5)
Typical Timing: 94 ± 16 ns
Statistics of 1024 samples:
Minimum: -5
Median: 0
Maximum: 5
Mean: -0.03125
Std Deviation: 1.6218811712712926
Distribution of 102400 samples:
-5: 0.20703125%
-4: 1.134765625%
-3: 4.333984375%
-2: 11.8212890625%
-1: 20.2890625%
0: 24.720703125%
1: 20.1728515625%
2: 11.400390625%
3: 4.4892578125%
4: 1.1845703125%
5: 0.24609375%
Random Floats:
Base Case
Output Analysis: Random.random()
Typical Timing: 32 ± 16 ns
Statistics of 1024 samples:
Minimum: 0.00116108845961993
Median: (0.4827456271240189, 0.48481111856276626)
Maximum: 0.9992939388590814
Mean: 0.48829838807105436
Std Deviation: 0.2890036798001988
Post-processor distribution of 102400 samples using round method:
0: 50.1025390625%
1: 49.8974609375%
Output Analysis: canonical()
Typical Timing: 32 ± 16 ns
Statistics of 1024 samples:
Minimum: 0.0002331581700841484
Median: (0.5054661877696423, 0.5069535563695092)
Maximum: 0.9997154446759824
Mean: 0.4957733335501641
Std Deviation: 0.2817270800287168
Post-processor distribution of 102400 samples using round method:
0: 49.8046875%
1: 50.1953125%
Output Analysis: random_float(0.0, 10.0)
Typical Timing: 32 ± 16 ns
Statistics of 1024 samples:
Minimum: 0.0036498404754798184
Median: (4.8452583440133665, 4.892052039805374)
Maximum: 9.995627006507686
Mean: 4.8954074539136245
Std Deviation: 2.928841306033409
Post-processor distribution of 102400 samples using floor method:
0: 10.0810546875%
1: 9.884765625%
2: 10.0986328125%
3: 9.9541015625%
4: 9.9287109375%
5: 9.7578125%
6: 10.08203125%
7: 10.068359375%
8: 10.1259765625%
9: 10.0185546875%
Base Case
Output Analysis: Random.triangular(0.0, 10.0, 5.0)
Typical Timing: 438 ± 13 ns
Statistics of 1024 samples:
Minimum: 0.3414921412754702
Median: (5.115301118823715, 5.117488744782021)
Maximum: 9.79109610016019
Mean: 5.056212027868304
Std Deviation: 2.056008489124207
Post-processor distribution of 102400 samples using round method:
0: 0.4892578125%
1: 4.177734375%
2: 7.982421875%
3: 12.0185546875%
4: 16.0341796875%
5: 18.763671875%
6: 16.01171875%
7: 11.9873046875%
8: 8.021484375%
9: 4.0078125%
10: 0.505859375%
Output Analysis: triangular(0.0, 10.0, 5.0)
Typical Timing: 32 ± 6 ns
Statistics of 1024 samples:
Minimum: 0.21944366484940703
Median: (4.9576027653575405, 4.957665347016224)
Maximum: 9.824324357960963
Mean: 4.939048187733266
Std Deviation: 2.066104368383957
Post-processor distribution of 102400 samples using round method:
0: 0.4873046875%
1: 4.0234375%
2: 8.0390625%
3: 12.0888671875%
4: 15.947265625%
5: 18.841796875%
6: 16.0478515625%
7: 11.9716796875%
8: 7.9814453125%
9: 4.048828125%
10: 0.5224609375%
Random Booleans:
Output Analysis: percent_true(33.33)
Typical Timing: 32 ± 15 ns
Statistics of 1024 samples:
Minimum: False
Median: False
Maximum: True
Mean: 0.330078125
Std Deviation: 0.4704707338273809
Distribution of 102400 samples:
False: 66.75%
True: 33.25%
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: 6875 ± 130 ns
Typical Timing: 65625 ± 672 ns
Typical Timing: 688375 ± 6119 ns
Fortuna.shuffle()
Typical Timing: 375 ± 1 ns
Typical Timing: 3375 ± 45 ns
Typical Timing: 32000 ± 89 ns
-------------------------------------------------------------------------
Total Test Time: 3.491 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.8.2.tar.gz
.
File metadata
- Download URL: Fortuna-3.8.2.tar.gz
- Upload date:
- Size: 158.3 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/1.13.0 pkginfo/1.4.2 requests/2.20.0 setuptools/41.0.1 requests-toolbelt/0.8.0 tqdm/4.27.0 CPython/3.7.3
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 624cd550d40828ec944dfe57657949b3374e77ff3aa5476279ada44ab575a70e |
|
MD5 | 64e8c13e0d518430d09725fea5168479 |
|
BLAKE2b-256 | be9050927cb4a714c0f96e2629f50e0f12afcb7a62b536270b976397ecadb57c |
Provenance
File details
Details for the file Fortuna-3.8.2-cp37-cp37m-macosx_10_9_x86_64.whl
.
File metadata
- Download URL: Fortuna-3.8.2-cp37-cp37m-macosx_10_9_x86_64.whl
- Upload date:
- Size: 138.9 kB
- Tags: CPython 3.7m, macOS 10.9+ x86-64
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/1.13.0 pkginfo/1.4.2 requests/2.20.0 setuptools/41.0.1 requests-toolbelt/0.8.0 tqdm/4.27.0 CPython/3.7.3
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 1376b08e5623888a376d9031aae36b6372def74b0bd7fcb3656995f2627f1006 |
|
MD5 | de066487b19f1524f90f89d4ab4c454c |
|
BLAKE2b-256 | 6d09bb2fdc6aec091e6b0c77744f1fa79a7da3134d3894aafa7902c7924ffd1a |