I want to generate random lengths and patterns of square brackets, for example, []] [[]] [[] [[]] []
I have so far managed to get my program to create parentheses randomly, but randomly in terms of how many times it generates them, so currently my program is giving me results like
[] [] [] [] [] []
[] [] []
[] [] [] [] []
Thus, in parentheses there is no randomness, only randomness in the number of displayed brackets.
I want to know how I can make the order of brackets random aswell as the number of brackets in the display.
Here is my code so far,
import random
import string
def randomGen(N):
return random.randint(1,N)
char1 = '['
char2 = ']'
finalist = []
newList = []
newList2 = []
newValue = randomGen(99)
for i in range(newValue):
newList = char1
newList2 = char2
finalist.append(newList + newList2)
for everChar in finalist:
print everChar,
Thank.
source
share