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
TrueorFalsebased on a probability (themaybefunction)return random data
- 
gramfuzz.rand.data(length, charset)[source]¶ Generate
lengthrandom characters from charsetcharset- 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
Truewithprobprobability.- Parameters
 prob (float) – The probability
Truewill be returned- Returns
 bool
- 
gramfuzz.rand.randfloat(a, b=None)[source]¶ Return a random float
- Parameters
 a (float) – Either the minimum value (inclusive) if
bis set, or
the maximum value if
bis 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
bis set, or
the maximum value if
bis 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
itemsusing theprobabilitiestuple/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])