rand

Gramfuzz uses a simple module (rand) as an interface to Python’s built-in random module.

Since all random actions/function calls get piped through gramfuzz.rand, enforcing a random seed to be used across all of gramfuzz is a simple matter.

rand Reference Documentation

rand is a module that provides random utilities, such as:

  • globally setting a seed value

  • random integers between a range

  • random floats between a range

  • return True or False based on a probability (the maybe function)

  • return random data

gramfuzz.rand.data(length, charset)[source]

Generate length random characters from charset charset

Parameters
  • length (int) – The number of characters to randomly generate

  • charset (str) – The charset of characters to choose from

Returns

str

gramfuzz.rand.maybe(prob=0.5)[source]

Return True with prob probability.

Parameters

prob (float) – The probability True will be returned

Returns

bool

gramfuzz.rand.randfloat(a, b=None)[source]

Return a random float

Parameters

a (float) – Either the minimum value (inclusive) if b is set, or

the maximum value if b is not set (non-inclusive, in which case the minimum is implicitly 0.0) :param float b: The maximum value to generate (non-inclusive) :returns: float

gramfuzz.rand.randint(a, b=None)[source]

Return a random integer

Parameters

a (int) – Either the minimum value (inclusive) if b is set, or

the maximum value if b is not set (non-inclusive, in which case the minimum is implicitly 0) :param int b: The maximum value to generate (non-inclusive) :returns: int

gramfuzz.rand.random() → x in the interval [0, 1).
gramfuzz.rand.seed(val)[source]

Set the seed for any subsequent random values/choices

Parameters

val – The random seed value

gramfuzz.rand.weighted_choice(items, probabilities)[source]

Returns a randomly-chosen item from items using the probabilities tuple/list to determine probabilities.

Assumes all weights add up to 1.0

E.g.

# 10% chance of 1
# 30% chance of 2
# 60% chance of 3
weighted_choice([1, 2, 3], [0.1, 0.3, 0.6])