mirror of
https://github.com/sbrl/research-rainfallradar
synced 2024-12-22 14:15:01 +00:00
shuffle: add random seed env var
This commit is contained in:
parent
ac040717e6
commit
20092c6829
1 changed files with 13 additions and 2 deletions
|
@ -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
|
||||
|
|
Loading…
Reference in a new issue