diff --git a/aimodel/src/lib/dataset/primitives/shuffle.py b/aimodel/src/lib/dataset/primitives/shuffle.py index 487fe2c..8e4e8a8 100644 --- a/aimodel/src/lib/dataset/primitives/shuffle.py +++ b/aimodel/src/lib/dataset/primitives/shuffle.py @@ -1,5 +1,9 @@ +import os + from copy import deepcopy -from random import randint +import random + +from loguru import logger def shuffle(lst): @@ -9,10 +13,17 @@ def shuffle(lst): @param lst list The list to shuffle. @return list The a new list that is a shuffled copy of the original. """ + tmplist = deepcopy(lst) m = len(tmplist) + + if RANDSEED in os.environ: + seed = os.environ["RANDSEED"] + random.seed(seed) + logger.info(f"Random seed set to {seed}, first 3 values: {random.randint(0, m)}, {random.randint(0, m)}, {random.randint(0, m)}") + while (m): m -= 1 - i = randint(0, m) + i = random.randint(0, m) tmplist[m], tmplist[i] = tmplist[i], tmplist[m] return tmplist