samedi 9 janvier 2021

random.sample() how to control reproducibility

Is there a way to control random.sample()? I fix seed that standard way:

def seed_everything(seed=42):
    random.seed(seed)
    os.environ['PYTHONHASHSEED'] = str(seed)
    np.random.seed(seed)
    torch.manual_seed(seed)
    torch.cuda.manual_seed(seed)
    torch.backends.cudnn.deterministic = True
 
seed_everything(42)

Nevertheless the result of code below is different every time:

idxT=[0,1,2,3,4,5,6]
idxT = [
        idxT[j] for j in sorted(random.sample(range(len(idxT)), 3))
    ]
idxT



Aucun commentaire:

Enregistrer un commentaire