random

shuffle_together

satella.random.shuffle_together(*args)

args, being sequences of equal length, will be permuted in such a way that their indices will still correspond to each other.

So given:

>>> a = [1, 2, 3]
>>> b = ['a', 'b', 'c']
>>> c = shuffle_together(a, b)

Might equal

>>> c == [[3, 1, 2], ['c', 'a', 'b']]
Parameters:

args (Sequence) –

Return type:

List[List]

random_binary

satella.random.random_binary(length)

Return a random bytes string of given length.

An attempt will be made to utilize /dev/random, if exists

Parameters:

length (int) – length of string to generate

Return type:

bytes

random_word

satella.random.random_word(length, choice='abcdefghijklmnopqrstuvwxyz', join_fun=<function <lambda>>)

Build and return a random word of provided length.

The word will be built by calling join_fun with length of arguments picked at random from choice.

Best used with strings. Provide a word length, a string to choose from as choice (defaults to string.ascii_lowercase). Will return by default a string (which coincidentally happens to be a sequence of strings, albeit one-character ones).

Parameters:
  • length (int) – length of the word

  • choice (Sequence[T]) – a range of characters to use. By default is string.ascii_lowercase

  • join_fun (Callable[[List[T]], T]) – an argument to be called with a list of randomly picked values. Defaults to ‘’.join(args), so your T must be a string. If you’re passing a different type, remember to alter this function because the default one expects strings!

Returns:

a random word

Return type:

Sequence[T]