vendredi 9 octobre 2020

How to fix the seed while using random.choice? [duplicate]

This is a follow up to my question posted here

import random

l = [11.1, 22.2, 33.3, 11.1, 33.3, 33.3, 22.2, 55.5]

l_new = random.choices(l, k=30)
print(l_new)

random.choice generates a new list using values from l. I would like to create the same output each time by fixing the seed of random.choice.

Suggestions will be really helpful.

Output obtained: Run1:

[33.3, 33.3, 33.3, 33.3, 55.5, 11.1, 11.1, 55.5, 22.2, 11.1, 33.3, 11.1, 55.5, 22.2, 33.3, 22.2, 22.2, 33.3, 55.5, 11.1, 11.1, 55.5, 11.1, 33.3, 11.1, 33.3, 33.3, 22.2, 33.3, 11.1]

Run2:

[22.2, 11.1, 33.3, 55.5, 33.3, 22.2, 33.3, 11.1, 22.2, 11.1, 11.1, 33.3, 33.3, 22.2, 33.3, 22.2, 11.1, 11.1, 55.5, 55.5, 33.3, 11.1, 55.5, 22.2, 33.3, 33.3, 55.5, 22.2, 22.2, 33.3]

Expected:

Run1:

[22.2, 11.1, 33.3, 55.5, 33.3, 22.2, 33.3, 11.1, 22.2, 11.1, 11.1, 33.3, 33.3, 22.2, 33.3, 22.2, 11.1, 11.1, 55.5, 55.5, 33.3, 11.1, 55.5, 22.2, 33.3, 33.3, 55.5, 22.2, 22.2, 33.3]

Run2:

[22.2, 11.1, 33.3, 55.5, 33.3, 22.2, 33.3, 11.1, 22.2, 11.1, 11.1, 33.3, 33.3, 22.2, 33.3, 22.2, 11.1, 11.1, 55.5, 55.5, 33.3, 11.1, 55.5, 22.2, 33.3, 33.3, 55.5, 22.2, 22.2, 33.3]



Aucun commentaire:

Enregistrer un commentaire