The function here just generates a random list of 0s and 1s. It's for later use in a game. So I need to take the list generated by binary_gen and convert it to a string. I've tried using .join but I just get an error message back. Is there any way for me to convert the output from binary_gen to a string? Or is there another way I can generate a random sequence of 0s and 1s?
import random
def random_binary():
min_length = 4
max_length = 8
binary_gen = [random.randrange(0,2,1) for _ in range \
(random.randint(min_length,max_length))]
print (binary_gen)
random_binary()
Update:
import random
def random_binary():
min_length = 4
max_length = 8
binary_gen = [random.randrange(0,2,1) for _ in range \
(random.randint(min_length,max_length))]
binary_string = "".join(binary_gen)
print (binary_string)
random_binary()
And I get: TypeError: sequence item 0: expected str instance, int found