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:
RandomGeneratorAn 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.
- class FoxDot.lib.Patterns.Generators.PDelta(deltas, start=0)[source]¶
Bases:
GeneratorPattern
- class FoxDot.lib.Patterns.Generators.PFibMod(**kwargs)[source]¶
Bases:
GeneratorPatternReturns the fibonacci sequence – maybe a bad idea
- class FoxDot.lib.Patterns.Generators.PIndex(**kwargs)[source]¶
Bases:
GeneratorPatternReturns the index being accessed
- class FoxDot.lib.Patterns.Generators.PRand(start, stop=None, **kwargs)[source]¶
Bases:
RandomGeneratorReturns a random integer between start and stop. If start is a container-type it returns a random item for that container.
- class FoxDot.lib.Patterns.Generators.PSquare(**kwargs)[source]¶
Bases:
GeneratorPatternReturns the square of the index being accessed
- class FoxDot.lib.Patterns.Generators.PTree(n=0, f=<function PTree.<lambda>>, choose=<function PTree.<lambda>>, **kwargs)[source]¶
Bases:
RandomGeneratorTakes 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.
- class FoxDot.lib.Patterns.Generators.PWalk(max=7, step=1, start=0, **kwargs)[source]¶
Bases:
RandomGenerator
- class FoxDot.lib.Patterns.Generators.PWhite(lo=0, hi=1, **kwargs)[source]¶
Bases:
RandomGeneratorReturns random floating point values between ‘lo’ and ‘hi’
- class FoxDot.lib.Patterns.Generators.PZ12(tokens=[1, 0], p=[1, 0.5])[source]¶
Bases:
GeneratorPatternImplementation 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.
- class FoxDot.lib.Patterns.Generators.PwRand(values, weights, **kwargs)[source]¶
Bases:
RandomGenerator
- class FoxDot.lib.Patterns.Generators.RandomGenerator(*args, **kwargs)[source]¶
Bases:
GeneratorPattern