hbutils.random.sequence

Overview:

Random function about the sequences.

shuffle

hbutils.random.sequence.shuffle(seq: Collection[_ElementType], *, random=None)[source]
Overview:

Shuffle the given collection.

Arguments:
  • seq (Collection[_ElementType]): Original sequence to be shuffled.

  • random: Random instance, default is None which means use the native instance from random module.

Examples::
>>> shuffle([1, 2, 3])
[3, 1, 2]  # just one of the possiblities
>>> shuffle(('a', 1, 'b', 2))
('b', 1, 2, 'a')  # the tuple type will be kept

multiple_choice

hbutils.random.sequence.multiple_choice(seq: Collection[_ElementType], count: int, *, put_back: bool = False, random=None)[source]
Overview:

Choose multiple items from the given sequence seq.

Arguments:
  • seq (Collection[_ElementType]): Original sequence to be chosen.

  • count (int): Choose count. Should be no more than length of seq

    when put back is disabled.

  • put_back (bool): Put back the chosen items or not, default is False

    which means do not put back, the chosen items will be unique.

  • random: Random instance, default is None which means use the native instance

    from random module.

Examples::
>>> multiple_choice([1, 2, 3], 2)
[2, 3]  # one of the possibilities
>>> multiple_choice([1, 2, 3], 2, put_back=True)
[2, 2]  # this is possible when put back option is on