mirror of
https://github.com/sbrl/research-rainfallradar
synced 2024-11-22 09:13: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 copy import deepcopy
|
||||||
from random import randint
|
import random
|
||||||
|
|
||||||
|
from loguru import logger
|
||||||
|
|
||||||
|
|
||||||
def shuffle(lst):
|
def shuffle(lst):
|
||||||
|
@ -9,10 +13,17 @@ def shuffle(lst):
|
||||||
@param lst list The list to shuffle.
|
@param lst list The list to shuffle.
|
||||||
@return list The a new list that is a shuffled copy of the original.
|
@return list The a new list that is a shuffled copy of the original.
|
||||||
"""
|
"""
|
||||||
|
|
||||||
tmplist = deepcopy(lst)
|
tmplist = deepcopy(lst)
|
||||||
m = len(tmplist)
|
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):
|
while (m):
|
||||||
m -= 1
|
m -= 1
|
||||||
i = randint(0, m)
|
i = random.randint(0, m)
|
||||||
tmplist[m], tmplist[i] = tmplist[i], tmplist[m]
|
tmplist[m], tmplist[i] = tmplist[i], tmplist[m]
|
||||||
return tmplist
|
return tmplist
|
||||||
|
|
Loading…
Reference in a new issue