Skip to content

Instantly share code, notes, and snippets.

@eidas

eidas/kai_square.py

Created Mar 8, 2012
Embed
What would you like to do?
Pythonの乱数評価用
import random
random.seed()
def rand(y,randmax,n):
for i in range(randmax+1):
y[i] = 0
for i in range(randmax*n+1):
r = random.randint(0,randmax)
y[r] += 1
return y
def kai_square(y,randmax,n):
k=0
for i in range(randmax+1):
k += float(pow(y[i]-n, 2))/float(n)
return k
y={}
y=rand(y,255,100)
kai=kai_square(y,255,100)
print kai
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment