FoxDot.lib.Patterns.Generators

This module contains all the sub-classes of GeneratorPattern used in FoxDot. Unlike a Pattern, a GeneratorPattern does not contain a list that is iterated over or indexed but returns a value based on the index and an internal function. For example, PRand returns a random value from a list of values. It will always return the same value for the same index as it stores this in its internal cache. Pattern methods such as rotate or palindrome are not available from the GeneratorPattern class but slicing generators will return a Pattern object from which these methods can be called e.g.

>>> gen = PRand([0,1,2])
>>> pat = gen[:5]
P[0, 1, 0, 2, 1]
>>> pat.rotate()
P[1, 0, 2, 1, 0]

Mathematical operations do work in the same way as they do in Patterns.

>>> gen1 = PRand([0,1,2])
>>> gen2 = gen1 + 10
>>> gen1[:5]
P[0, 2, 2, 1, 0]
>>> gen2[:5]
P[10, 12, 12, 11, 10]
class FoxDot.lib.Patterns.Generators.PChain(mapping, **kwargs)[source]

Bases: RandomGenerator

An example of a Markov Chain generator pattern. The mapping argument should be a dictionary of keys whose values are a list/pattern of possible destinations.

func(*args, **kwargs)[source]
class FoxDot.lib.Patterns.Generators.PDelta(deltas, start=0)[source]

Bases: GeneratorPattern

func(index)[source]
class FoxDot.lib.Patterns.Generators.PFibMod(**kwargs)[source]

Bases: GeneratorPattern

Returns the fibonacci sequence – maybe a bad idea

func(index)[source]
class FoxDot.lib.Patterns.Generators.PIndex(**kwargs)[source]

Bases: GeneratorPattern

Returns the index being accessed

func(index)[source]
class FoxDot.lib.Patterns.Generators.PRand(start, stop=None, **kwargs)[source]

Bases: RandomGenerator

Returns a random integer between start and stop. If start is a container-type it returns a random item for that container.

choose()[source]
func(index)[source]
string()[source]

Used in PlayString to show a PRand in curly braces

class FoxDot.lib.Patterns.Generators.PSquare(**kwargs)[source]

Bases: GeneratorPattern

Returns the square of the index being accessed

func(index)[source]
class FoxDot.lib.Patterns.Generators.PTree(n=0, f=<function PTree.<lambda>>, choose=<function PTree.<lambda>>, **kwargs)[source]

Bases: RandomGenerator

Takes a starting value and two functions as arguments. The first function, f, must take one value and return a container-type of values and the second function, choose, must take a container-type and return a single value. In essence you are creating a tree based on the f(n) where n is the last value chosen by choose.

func(index)[source]
class FoxDot.lib.Patterns.Generators.PWalk(max=7, step=1, start=0, **kwargs)[source]

Bases: RandomGenerator

func(index)[source]
class FoxDot.lib.Patterns.Generators.PWhite(lo=0, hi=1, **kwargs)[source]

Bases: RandomGenerator

Returns random floating point values between ‘lo’ and ‘hi’

func(index)[source]
class FoxDot.lib.Patterns.Generators.PZ12(tokens=[1, 0], p=[1, 0.5])[source]

Bases: GeneratorPattern

Implementation of the PZ12 algorithm for predetermined random numbers. Using an irrational value for p, however, results in a non-determined order of values. Experimental, only works with 2 values.

func(index)[source]
class FoxDot.lib.Patterns.Generators.PwRand(values, weights, **kwargs)[source]

Bases: RandomGenerator

choose()[source]
func(index)[source]
class FoxDot.lib.Patterns.Generators.PxRand(start, stop=None, **kwargs)[source]

Bases: PRand

func(index)[source]
class FoxDot.lib.Patterns.Generators.RandomGenerator(*args, **kwargs)[source]

Bases: GeneratorPattern

choice(*args, **kwargs)[source]
init_random(*args, **kwargs)[source]

To be called at the end of the __init__

randint(*args, **kwargs)[source]
classmethod set_override_seed(seed)[source]
triangular(*args, **kwargs)[source]