document.write('
Data hosted with ♥ by Pastebin.com - Download Raw - See Original
  1. #!/usr/bin/python
  2. from fractions import *
  3. from math import *
  4. import sys
  5.  
  6. def ent(m):
  7.     n = log10(m)
  8.     if float(n).is_integer():
  9.         #print "Entero en decimal"
  10.         deci = True
  11.     else:
  12.         #print "Flotante en decimal"
  13.         deci = False
  14.  
  15.     n = (log10(m))/(log10(2))
  16.     if float(n).is_integer():
  17.         #print "entero binario"
  18.         bina = True
  19.     else:
  20.         #print "flotante binario"
  21.         bina = False
  22.        
  23.     if deci == True:
  24.         ent = 1
  25.         return ent
  26.     elif bina == True:
  27.         ent = 1
  28.         return ent
  29.     else:
  30.         ent = 0
  31.         return ent
  32.  
  33.  
  34. def periodo(m):
  35.     if (m%10==0):
  36.         print "Es Decimal"
  37.         n = log10(m)
  38.         if (n >= 5):
  39.             n = n-2
  40.             pe= int(pow(10,n) * 5)
  41.             print "p.e. = ", pe
  42.         else:
  43.             l1 = int(pow(5, n-1)*4)
  44.             l2 = int(pow(2, n-1))
  45.             pe = int((l1 * l2) / gcd(l1, l2))
  46.             print "p.e. = ", pe
  47.     elif(m%2==0):
  48.         pe = m/4
  49.         print "Es Binario"
  50.         print "p.e. = ", pe
  51.  
  52.     return pe
  53. def tabla(a,x0,x0inicial,m,pe):
  54.     print "n    X0        aX0 mod m          Xn+1       Numeros Rectangulares" 
  55.     for i in range(pe):
  56.         i += 1
  57.         mod = ((a*x0)%m)
  58.         multi = (a*x0)/m
  59.         nr = float((mod+.0)/(m+.0))
  60.         print i, "   ", x0, "    ",  multi, " + ", mod,"/", m, "       ", mod, "            ", mod, "/", m, " =  %f"%(nr)
  61.         x0 = mod
  62.         if x0inicial == mod and i == pe:
  63.             print "Generador congruencial multiplicativo Confiable"
  64.             sys.exit()
  65.         elif x0inicial == mod:
  66.             print "Generador congruencial multiplicativo No Confiable"
  67.             sys.exit()
  68.         elif x0inicial != mod and i == pe:
  69.             print "Generador congruencial multiplicativo No Confiable"
  70.             sys.exit()
  71.  
  72. def main():
  73.     done = False
  74.     while done == False:
  75.         a = input("Dame una constante multiplicativa a ")
  76.         x0 = input("Dame una semilla inicial X0 ")
  77.         m = input("Dame el modulo m ")
  78.         x0inicial = x0
  79.         lal = ent(m)
  80.         if lal == 1:
  81.             pe = periodo(m)
  82.             tabla(a,x0,x0inicial,m,pe)
  83.            
  84.         else:
  85.             print "No se puede realizar, porfavor ingrese un valor decimal (10^n) o uno binario (2^n)"
  86.        
  87. main()
');