Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/usr/bin/python
- from fractions import *
- from math import *
- import sys
- def ent(m):
- n = log10(m)
- if float(n).is_integer():
- #print "Entero en decimal"
- deci = True
- else:
- #print "Flotante en decimal"
- deci = False
- n = (log10(m))/(log10(2))
- if float(n).is_integer():
- #print "entero binario"
- bina = True
- else:
- #print "flotante binario"
- bina = False
- if deci == True:
- ent = 1
- return ent
- elif bina == True:
- ent = 1
- return ent
- else:
- ent = 0
- return ent
- def periodo(m):
- if (m%10==0):
- print "Es Decimal"
- n = log10(m)
- if (n >= 5):
- n = n-2
- pe= int(pow(10,n) * 5)
- print "p.e. = ", pe
- else:
- l1 = int(pow(5, n-1)*4)
- l2 = int(pow(2, n-1))
- pe = int((l1 * l2) / gcd(l1, l2))
- print "p.e. = ", pe
- elif(m%2==0):
- pe = m/4
- print "Es Binario"
- print "p.e. = ", pe
- return pe
- def tabla(a,x0,x0inicial,m,pe):
- print "n X0 aX0 mod m Xn+1 Numeros Rectangulares"
- for i in range(pe):
- i += 1
- mod = ((a*x0)%m)
- multi = (a*x0)/m
- nr = float((mod+.0)/(m+.0))
- print i, " ", x0, " ", multi, " + ", mod,"/", m, " ", mod, " ", mod, "/", m, " = %f"%(nr)
- x0 = mod
- if x0inicial == mod and i == pe:
- print "Generador congruencial multiplicativo Confiable"
- sys.exit()
- elif x0inicial == mod:
- print "Generador congruencial multiplicativo No Confiable"
- sys.exit()
- elif x0inicial != mod and i == pe:
- print "Generador congruencial multiplicativo No Confiable"
- sys.exit()
- def main():
- done = False
- while done == False:
- a = input("Dame una constante multiplicativa a ")
- x0 = input("Dame una semilla inicial X0 ")
- m = input("Dame el modulo m ")
- x0inicial = x0
- lal = ent(m)
- if lal == 1:
- pe = periodo(m)
- tabla(a,x0,x0inicial,m,pe)
- else:
- print "No se puede realizar, porfavor ingrese un valor decimal (10^n) o uno binario (2^n)"
- main()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement