EDIT: use cryptographically secure os.urandom
for true randomness
Python one-liner
You could install pythonpython and run the following command in your terminal
pythonpython3 -c 'import os; print(f"{int.from_bytes(os.urandom(1)):08b}")'
(might need to use python3
instead of python
at the beginning). Here you get 8
coin flips at once.
Python file
For a bit more flexibility you can also save the following code as the file coinflips.py
#!/usr/bin/env python3
import os, sys
def flip_coins_n_times(n:int):
nbytes = n//8 + bool(n%8)
# get random bytes, convert to bits (including leading zeros)
# finally remove excess and print
print(f"{int.from_bytes(os.urandom(nbytes), 'big'):0{8*nbytes}b}"[0:n])
if __name__ == '__main__':
# file is run from commandline
flip_coins_n_times(int(sys.argv[1]))
and run it from the command line as
python$ python3 coinflips.py 20
11100100011100100111
$
Here you can replace 20
by the number of coinflips you want