Created
December 14, 2014 20:27
-
-
Save whaleee/4a2ae06b6e5ef348c06c to your computer and use it in GitHub Desktop.
This file contains 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
def randomMod(A, B, X1, K, M): | |
if K == 0 or M == 0: | |
print 'Input Error' | |
return | |
addAux = aux(A, K, B) | |
output = [0,0,0,0,0] | |
output[0] = (A**(K-1))*X1 + addAux | |
output[1] = A*output[0] + B | |
output[2] = A*output[1] + B | |
output[3] = A*output[2] + B | |
output[4] = A*output[3] + B | |
#print output | |
for i in range(5): | |
output[i] = output[i] % M | |
print output | |
def aux(a, k, b): | |
i = 0 | |
res =0 | |
while i < k-1: | |
res += (a**i)*b | |
i += 1 | |
print 'end aux. res = ', res | |
return res |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment