SHARE
TWEET

Untitled

a guest May 19th, 2019 69 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. from scipy import special
  2. import math
  3. import random
  4.  
  5.  
  6.  
  7.  
  8. def LongestRunOfOnes(n):
  9.     if n >= 128 and n < 6272:
  10.         M = 8
  11.         K = 3
  12.         N = 16
  13.         pi = [0.2148, 0.3672, 0.2305, 0.1875]
  14.  
  15.     elif n >= 6272 and n < 750000:
  16.         M = 128
  17.         K = 5
  18.         N = 49
  19.         pi = [0.1174, 0.2430, 0.2493, 0.1752, 0.1027, 0.1124]
  20.  
  21.     elif n >= 750000:
  22.         M = 10000
  23.         K = 6
  24.         N = 75
  25.         pi = [0.0882, 0.2092, 0.2483, 0.1933, 0.1208, 0.0675, 0.0675, 0.0727]
  26.  
  27.     max_ones = 0
  28.     maxi = 0
  29.     maxes = []
  30.     ej = n // M
  31.     word1 = 0
  32.     word2 = M
  33.     for j in range(ej):
  34.         word = e[word1: word2]
  35.         for i in range(M):
  36.             #print(word, i, M)
  37.             if word[i] == '1':
  38.                 max_ones += 1
  39.                 maxi = max(max_ones, maxi)
  40.             else:
  41.                 max_ones = 0
  42.                 maxi = max(max_ones, maxi)
  43.         maxes.append(maxi)
  44.         maxi = 0
  45.         max_ones = 0
  46.         word1 += M
  47.         word2 += M
  48.     chi = 0
  49.     counts = []
  50.     for i in range(1, K + 2):
  51.         count = maxes.count(i)
  52.         counts.append(count)
  53.     for i in range(K + 1):
  54.         chi += ((counts[i] - N * pi[i])**2) / (N * pi[i])
  55.     igame = special.gammaincc(K / 2, chi / 2)
  56.     print(igame)
  57.     if igame >= 0.01:
  58.         print("random")
  59.     else:
  60.         print("non-random")
  61.  
  62. for i in range(100):
  63.     n = 128
  64.     x = random.getrandbits(n)
  65.     y = bin(x)[2:]
  66.     x = str(y)
  67.     print(y)
  68.     k = len(y)
  69.     e = "1100110000010101011011000100110011100000000000100100110101010001000100111101011010000000110101111100110011100" \
  70.         "1101101100010110010"
  71.     e = y
  72.     if k < 128:
  73.         i -=1
  74.     else:
  75.         LongestRunOfOnes(k)
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
Not a member of Pastebin yet?
Sign Up, it unlocks many cool features!
 
Top