iripau.random module

Generic and stand-alone random utilities.

iripau.random.one(items)[source]

Return a new list containing only one element from items.

Parameters:

items (List[Any]) – The items to choose from.

Return type:

List[Any]

Returns:

A list with only one of the items.

iripau.random.some(items, percentage=50, at_least=2, at_most=None)[source]

Return a new list containing some elements from items. Ordinality is preserved as much as possible.

Parameters:
  • items (List[Any]) – The items to choose from.

  • percentage (float) – This percentage of the items will be chosen.

  • at_least (int) – If specified, do not choose less than this amount of items.

  • at_most (int) – If specified, do not choose more that this amount of items.

Return type:

List[Any]

Returns:

Some items in the same order.

iripau.random.shuffled(items)[source]

Return a new list containing all of the elements from items but in a different order.

Parameters:

items (List[Any]) – The items to choose from.

Return type:

List[Any]

Returns:

The same items in different order.

iripau.random.random_string(length, chars='abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ')[source]

Return a string of the desired length containing randomly chosen characters from chars.

Parameters:
  • length (int) – How long the returned string will be.

  • chars (str) – Set of chars to choose from.

Return type:

str

Returns:

New string.