1

Im just messing around in python since im learning at the moment.

Im checking the NIST randomness beacon, and im parsing for the output, removing all letters and using it as a seed to generate random numbers, I append those to an array and save the array to a file but Im getting an error.

import numpy as np
import array as arr
import random
import urllib.request
import urllib.parse
import re

url = 'https://beacon.nist.gov/beacon/2.0/pulse/last'
f = urllib.request.urlopen(url)
data_set = str(f.read().decode('utf-8'))

#print(data_set)
#print(subStr)
#print(type(subStr))

subStr = data_set


subStr = re.findall(r'"outputValue" : "(.+?)"',data_set)
print(subStr)
print(type(subStr))
subStr  = ''.join(subStr)
print(type(subStr))
NIST_SEED = ''.join(filter(str.isdigit, subStr))
print(NIST_SEED)
NIST_SEED = float(NIST_SEED)


numbers = arr.array('d', [])
#print(numbers)

i = 0


for i in range(10):
#    randon_number = random.random()
    random_number = random.seed(NIST_SEED)
    numbers.extend([random_number])
print(numbers)


np.savetxt('data.out', numbers)

Im getting this error, I don't understand why im getting this since the "seed" is a float. Im trying to understand the error.

  File "generating_data.py", line 38, in <module>
    numbers.extend([random_number]) 
TypeError: must be real number, not NoneType

EDIT:

Im an absolute newbie in python and I have no idea about software development. Im just writing stuff to test things out and to understand concepts. The idea behind this was to try a few different things out and to write a script that is generating CPU load so that I can learn about multithreading or example. This might be a stupid way to do it and It might not even teach me anything idk yet.

dev
  • 651
  • 1
  • 6
  • 14
  • 1
    `random.seed()` seeds a random generator, and doesn't return anything. You need to actually generate random number with `random.random()` – clubby789 Jan 22 '20 at 10:18
  • You can input a number into random.seed(555) and it will generate a "random" number using that seed. Im trying to input a number that is a float. – dev Jan 22 '20 at 10:20
  • @dev ***It*** refers to random module, but the way to generate is `random.random()` https://stackoverflow.com/questions/22639587/random-seed-what-does-it-do – Ray Jan 22 '20 at 10:21
  • The docs (https://docs.python.org/3/library/random.html#random.seed) do not specify that `seed()` returns anything. If you run `print(random.seed(5))` alone, you will see that it returns None. – clubby789 Jan 22 '20 at 10:23

1 Answers1

1
random_number = random.seed(NIST_SEED)
for i in range(10):
    random_number = random.random()
    numbers.extend([random_number])

This will seed your random number generator, then use random.random() to generate the actual random numbers.

clubby789
  • 2,543
  • 4
  • 16
  • 32