I am looking for the best way (fast and elegant) to get a random boolean in python (flip a coin).
For the moment I am using random.randint(0, 1) or
random.randint(0, 1)
I like
np.random.rand() > .5
You could use the Faker library, it's mainly used for testing, but is capable of providing a variety of fake data.
Install: https://pypi.org/project/Faker/
>>> from faker import Faker >>> fake = Faker() >>> fake.pybool() True