Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- from scipy import special
- import math
- import random
- def LongestRunOfOnes(n):
- if n >= 128 and n < 6272:
- M = 8
- K = 3
- N = 16
- pi = [0.2148, 0.3672, 0.2305, 0.1875]
- elif n >= 6272 and n < 750000:
- M = 128
- K = 5
- N = 49
- pi = [0.1174, 0.2430, 0.2493, 0.1752, 0.1027, 0.1124]
- elif n >= 750000:
- M = 10000
- K = 6
- N = 75
- pi = [0.0882, 0.2092, 0.2483, 0.1933, 0.1208, 0.0675, 0.0675, 0.0727]
- max_ones = 0
- maxi = 0
- maxes = []
- ej = n // M
- word1 = 0
- word2 = M
- for j in range(ej):
- word = e[word1: word2]
- for i in range(M):
- #print(word, i, M)
- if word[i] == '1':
- max_ones += 1
- maxi = max(max_ones, maxi)
- else:
- max_ones = 0
- maxi = max(max_ones, maxi)
- maxes.append(maxi)
- maxi = 0
- max_ones = 0
- word1 += M
- word2 += M
- chi = 0
- counts = []
- for i in range(1, K + 2):
- count = maxes.count(i)
- counts.append(count)
- for i in range(K + 1):
- chi += ((counts[i] - N * pi[i])**2) / (N * pi[i])
- igame = special.gammaincc(K / 2, chi / 2)
- print(igame)
- if igame >= 0.01:
- print("random")
- else:
- print("non-random")
- for i in range(100):
- n = 128
- x = random.getrandbits(n)
- y = bin(x)[2:]
- x = str(y)
- print(y)
- k = len(y)
- e = "1100110000010101011011000100110011100000000000100100110101010001000100111101011010000000110101111100110011100" \
- "1101101100010110010"
- e = y
- if k < 128:
- i -=1
- else:
- LongestRunOfOnes(k)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement