0

In my following code i m running a lorentz chaotic equation from which i will get random numbers in terms of xs , ys and zs

import numpy as np
def lorenz(x, y, z, a=10,b=8/3,c=28 ):
            x_dot = a*(y -x) 
            y_dot = - y +c*x - x*z
            z_dot = -b*z + x*y
            return x_dot, y_dot, z_dot
       
dt = 0.01
num_steps =  10000
# Need one more for the initial values
xs = np.empty(num_steps + 1)
ys = np.empty(num_steps + 1)
zs = np.empty(num_steps + 1)


# Set initial values
xs[0], ys[0], zs[0]= (1,1,1)
# Step through "time", calculating the partial derivatives at the current point
# and using them to estimate the next point
for i in range(num_steps):
    x_dot, y_dot, z_dot= lorenz(xs[i], ys[i], zs[i])
    xs[i + 1] = xs[i] + (x_dot * dt)
    ys[i + 1] = ys[i] + (y_dot * dt)
    zs[i + 1] = zs[i] + (z_dot * dt)

I am actually trying to test the xs, ys and zs value for random number generating test via NIST 800 by using the code below

from __future__ import print_function

import math
from fractions import Fraction
from scipy.special import gamma, gammainc, gammaincc
# from gamma_functions import *
import numpy
import cmath
import random

#ones_table = [bin(i)[2:].count('1') for i in range(256)]
def count_ones_zeroes(bits):
    ones = 0
    zeroes = 0
    for bit in bits:
        if (bit == 1):
            ones += 1
        else:
            zeroes += 1
    return (zeroes,ones)

def runs_test(bits):
    n = len(bits)
    zeroes,ones = count_ones_zeroes(bits)

    prop = float(ones)/float(n)
    print("  prop ",prop)

    tau = 2.0/math.sqrt(n)
    print("  tau ",tau)

    if abs(prop-0.5) > tau:
        return (False,0.0,None)

    vobs = 1.0
    for i in range(n-1):
        if bits[i] != bits[i+1]:
            vobs += 1.0

    print("  vobs ",vobs)
      
    p = math.erfc(abs(vobs - (2.0*n*prop*(1.0-prop)))/(2.0*math.sqrt(2.0*n)*prop*(1-prop) ))
    success = (p >= 0.01)
    return (success,p,None)
print(runs_test(xs))
#%%
from __future__ import print_function

import math

def count_ones_zeroes(bits):
    ones = 0
    zeroes = 0
    for bit in bits:
        if (bit == 1):
            ones += 1
        else:
            zeroes += 1
    return (zeroes,ones)

def monobit_test(bits):
    n = len(bits)
    
    zeroes,ones = count_ones_zeroes(bits)
    s = abs(ones-zeroes)
    print("  Ones count   = %d" % ones)
    print("  Zeroes count = %d" % zeroes)
    
    p = math.erfc(float(s)/(math.sqrt(float(n)) * math.sqrt(2.0)))
    
    success = (p >= 0.01)
    return (success,p,None)
print(runs_test(xs))

the output which i m getting is false i.e

output: prop 0.00019998000199980003 tau 0.01999900007499375 (False, 0.0, None)

what should i do now?

Zewo
  • 153
  • 1
  • 12

1 Answers1

0

The Lorenz system is chaotic, not random. You implemented the differential equation solver well, but it seems that count_ones_zeroes doesn't do what its name implies, at least, not on the data you provide. on xs, it returns that (zeroes, ones) = (9999, 2), which is not what you want. The code checks the value within the xs array, i.e. an x value (e.g. 8.2) against 1, but x is a float between -20 and 20, so it will be usually non1, and will be counted as 0. Only x==1 will be counted as ones.

In python, int/int results in float, so there is no need to cast it to float, in contrast to e.g. C or C++, so instead of prop = float(ones)/float(n), you can write prop = ones/n Similar statements hold for +,- and *

DanielTuzes
  • 2,494
  • 24
  • 40
  • thanks @Daniel but the problem is that i need a NIST Suite which can really calculate the p values for my differential system . ur answer seem to be correct but the expected values are still not as per desire.. Although the system of differential equation is chaotic not random but still researcher use NIST test for their chaotic systems – Zewo Dec 04 '21 at 10:14
  • can u help me find a NIST python codes that will allow me to test my chaotic systems? – Zewo Dec 04 '21 at 10:15
  • Is [NIST 800](https://csrc.nist.gov/publications/sp800) a bunch of publications? Which one of them is used to test the quality of random number generators? Where are the papers that detail in what sense is it an appropriate tool? – DanielTuzes Dec 05 '21 at 13:18
  • 1
    https://doi.org/10.1016/j.vlsi.2021.03.006 one of the research article... where they used NIST for chaotic system data generated from the system of differential equation. Notice this is not just the one paper there are several research articles where chaotic data randomness is tested with NIST – Zewo Dec 09 '21 at 08:33