iripau.random module¶
Generic and stand-alone random utilities.
- iripau.random.one(items)[source]¶
Return a new
listcontaining only one element fromitems.- Parameters:
items (
List[Any]) – The items to choose from.- Return type:
List[Any]- Returns:
A
listwith only one of theitems.
- iripau.random.some(items, percentage=50, at_least=2, at_most=None)[source]¶
Return a new
listcontaining some elements fromitems. Ordinality is preserved as much as possible.- Parameters:
items (
List[Any]) – The items to choose from.percentage (
float) – This percentage of theitemswill be chosen.at_least (
int) – If specified, do not choose less than this amount ofitems.at_most (
int) – If specified, do not choose more that this amount ofitems.
- Return type:
List[Any]- Returns:
Some
itemsin the same order.
- iripau.random.shuffled(items)[source]¶
Return a new
listcontaining all of the elements fromitemsbut in a different order.- Parameters:
items (
List[Any]) – The items to choose from.- Return type:
List[Any]- Returns:
The same
itemsin different order.
- iripau.random.random_string(length, chars='abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ')[source]¶
Return a string of the desired
lengthcontaining randomly chosen characters fromchars.- Parameters:
length (
int) – How long the returned string will be.chars (
str) – Set of chars to choose from.
- Return type:
str- Returns:
New string.