For my project I used Henon map to generate (pseudo)-random number. I used the following code to generate the matrix of (pseudo)-random number.
def generate_by_henonmap(dimension, key):
x = key[0]
y = key[1]
# Total Number of bitSequence produced
sequenceSize = dimension * dimension * 8
bitSequence = [] # Each bitSequence contains 8 bits
byteArray = [] # Each byteArray contains m bitSequence
Matrix = [] # Each Matrix contains m*n byteArray
for i in range(sequenceSize):
# Classical Henon map have values of a = 1.4 and b = 0.3
xN = y + 1 - 1.4 * x**2
yN = 0.3 * x
x = xN
y = yN
if xN <= 0.4:
bit = 0
else:
bit = 1
try:
bitSequence.append(bit)
except:
bitSequence = [bit]
if i % 8 == 7:
decimal = dec(bitSequence)
try:
byteArray.append(decimal)
except:
byteArray = [decimal]
bitSequence = []
byteArraySize = dimension*8
if i % byteArraySize == byteArraySize-1:
try:
Matrix.append(byteArray)
except:
Matrix = [byteArray]
byteArray = []
return Matrix
Before I use this code in my production I test the randomness by NIST Test suite from this but got this result:
Eligible test from NIST-SP800-22r1a:
-monobit
-frequency_within_block
-runs
-longest_run_ones_in_a_block
-dft
-non_overlapping_template_matching
-serial
-approximate_entropy
-cumulative sums
-random_excursion
-random_excursion_variant
Test results:
- PASSED - score: 0.525 - Monobit - elapsed time: 0 ms
- PASSED - score: 0.999 - Frequency Within Block - elapsed time: 0 ms
- FAILED - score: 0.0 - Runs - elapsed time: 1 ms
- FAILED - score: 0.002 - Longest Run Ones In A Block - elapsed time: 0 ms
- FAILED - score: 0.004 - Discrete Fourier Transform - elapsed time: 2 ms
- PASSED - score: 0.899 - Non Overlapping Template Matching - elapsed time: 8 ms
- FAILED - score: 0.0 - Serial - elapsed time: 54 ms
- FAILED - score: 0.0 - Approximate Entropy - elapsed time: 102 ms
- PASSED - score: 0.887 - Cumulative Sums - elapsed time: 4 ms
- FAILED - score: 0.11 - Random Excursion - elapsed time: 28 ms
- PASSED - score: 0.678 - Random Excursion Variant - elapsed time: 1 ms
I thought Chaotic map can generate enough randomness but the result was so frustrating. Is there any logical error inside the code which produce this poor result? I guess the way it generate the bit sequence of the number create the issue.
if xN <= 0.4:
bit = 0
else:
bit = 1
Is there any better implementation of the chaotic map to produce (pseudo)-random number?