Last active
April 8, 2019 08:01
-
-
Save kuboon/7e2ed9087b33a771d0dee3f3305f5af6 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import random | |
import struct | |
N=32 | |
def rp(a) : | |
a=list(range(0,32)) | |
x=0 | |
for i in range(0,N-2) : | |
j=(random.randint(0,N-i-2)) + i + 1 | |
x=a[j] | |
a[j]=a[i] | |
a[i]=x | |
if(a[N-1]==N-1) : | |
a[N-1]=a[N-2] | |
a[N-2]=N-1 | |
def toInt(a) : | |
i=0 | |
s=1 | |
ret=0 | |
for i in range(0,32) : | |
ret +=s*a[i] | |
s *= 2 | |
ret << 1 | |
return ret | |
def p_rand() : | |
first=1 | |
a=[1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0] | |
# 初回実行なら | |
if(first) : | |
# 初期化する | |
first = 0 | |
x=range(0,32) | |
y=range(0,32) | |
inv_x=list(range(0,32)) | |
tmp=list(range(0,32)) | |
rp(x) | |
rp(y) | |
for i in range(0,32) : | |
inv_x[x[i]]=i | |
# 初期化終わり | |
for i in range(0,32) : | |
tmp[i]=x[y[inv_x[i]]] | |
y=tmp | |
return toInt(a) | |
file = open("rand.dat","wb") | |
j=0 | |
while(j<1000000) : | |
a=p_rand() | |
file.write(struct.pack("B",a)) | |
j=j+1 | |
file.close() | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment