randomShuffle

pyagrum.randomShuffle(seq)

Shuffle a sequence in place with the random generator of pyAgrum.

For a given seed (see pyagrum.initRandom), the order is the same on every platform, and the same as the shuffles of pyAgrum (such as the random order of the variables of BNDatabaseGenerator).

Parameters:

seq (list) – a mutable sequence (supporting len, indexing and slice assignment)

Return type:

None

Example

import pyagrum as gum

gum.initRandom(42)
names = ["A", "B", "C", "D", "E"]
gum.randomShuffle(names)  # in place
names
# ['B', 'D', 'E', 'C', 'A']
sorted(names)
# ['A', 'B', 'C', 'D', 'E']
gum.initRandom(42)  # same seed: same order, on every platform
other = ["A", "B", "C", "D", "E"]
gum.randomShuffle(other)
other == names
# True