vendredi 27 octobre 2017

how to create a random list with vaues that are allowed to exist serveral times

I want to create a random list with 100 elements. So far, so good...

Example 1: works fine, because the function has a range which is big enough not to repeat any value

list = random.sample(range(1,200),100)

Example 2: Does not work, because the range is to small (Sample is larger than population)

list = random.sample(range(50,80),100)

I am looking for a solution how to create that random list with more values than the range and it is no Problem that the elements exists several times.

Thanks for your answers !




Aucun commentaire:

Enregistrer un commentaire