G
G
George1232019-10-30 15:35:16
Python
George123, 2019-10-30 15:35:16

How to get a binary sequence in numpy using mt19937?

You need to get a binary sequence using the Mersenne Vortex. There was an idea to use the built-in python random like this:

import random as rd
p=[]
k=int(1.1*10**8)
for i in range(k):
  p.append(rd.getrandbits(1))
#print(p)

s=''
for i in p:
  s+=str(i)
a=p.count(0)
b=p.count(1)
f = open('sec.txt', 'w')
f.write(s)
f.close()
print(a,b)

but in the documentation I did not find an explicit indication that the implementation of exactly mt19937 is used (this is important), so I began to look towards numpy, where it is already clearly stated that this particular algorithm is used. But in trying to figure out how to work with the generator in this library, I didn’t come to anything. Tell me, please, how to get a binary sequence from mt19937 in numpy, so that later all 0 and 1 can be written to a file? (It is important that the entire sequence from one grain be obtained)

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question