jeudi 27 août 2020

Difference between randint and sample in python

I have tried to generate random codes and tried both

sample([0..9],x)

And

[randint(0,9) for i in range(x)]

When I first used sample I noticed that it doesn't generate numbers like "2222222" it generate more distributed numbers While randint is more likely to generate numbers like "2222222".

What's the difference between both? and how I can choose the best method to generate random numbers for different cases?




Aucun commentaire:

Enregistrer un commentaire