import numpy as np
import matplotlib.pyplot as plt
def binString(n):
binS = np.random.randint(0,2,100)
s = ''.join(map(str,binS))
return s
def rle(s):
current = s[0]
count = 0
runLength = []
for char in s:
if char == current:
count += 1
else:
runLength.append(count)
current = char
count = 1
runLength.append(count)
return np.array(runLength)
def binStringHist(s):
rl = rle(s)
plt.hist(rl)
plt.show()
s1 = binString(100)
binStringHist(s1)
s2 = '0010101011101010101010101010101010101001010101010101010100100101010111010101010101010100101000101010'
binStringHist(s2)