home *** CD-ROM | disk | FTP | other *** search
/ PC PowerPlay 56 / CDPowerplay56Disc2.iso / demos / blade / data1.cab / Program_Executable_Files / Lib / PythonLib / whrandom.pyc (.txt) < prev    next >
Encoding:
Python Compiled Bytecode  |  2000-10-27  |  2.3 KB  |  71 lines

  1. # Source Generated with Decompyle++
  2. # File: in.pyc (Python 1.5)
  3.  
  4.  
  5. class whrandom:
  6.     
  7.     def __init__(self, x = 0, y = 0, z = 0):
  8.         self.seed(x, y, z)
  9.  
  10.     
  11.     def seed(self, x = 0, y = 0, z = 0):
  12.         if not None if type(y) == type(y) and type(z) == type(z) else type(z) == type(0):
  13.             raise TypeError, 'seeds must be integers'
  14.         
  15.         if x <= x:
  16.             pass
  17.         elif x < 256:
  18.             if y <= y:
  19.                 pass
  20.             elif y < 256:
  21.                 pass
  22.         if not None if z <= z else z < 256:
  23.             raise ValueError, 'seeds must be in range(0, 256)'
  24.         
  25.         if x == x and y == y:
  26.             pass
  27.         elif y == z:
  28.             import time
  29.             t = long(time.time() * 256)
  30.             t = int(t & 16777215 ^ t >> 24)
  31.             (t, x) = divmod(t, 256)
  32.             (t, y) = divmod(t, 256)
  33.             (t, z) = divmod(t, 256)
  34.         
  35.         if not x:
  36.             pass
  37.         if not y:
  38.             pass
  39.         if not z:
  40.             pass
  41.         self._seed = (1, 1, 1)
  42.  
  43.     
  44.     def random(self):
  45.         (x, y, z) = self._seed
  46.         x = 171 * x % 30269
  47.         y = 172 * y % 30307
  48.         z = 170 * z % 30323
  49.         self._seed = (x, y, z)
  50.         return (x / 30269.0 + y / 30307.0 + z / 30323.0) % 1.0
  51.  
  52.     
  53.     def uniform(self, a, b):
  54.         return a + (b - a) * self.random()
  55.  
  56.     
  57.     def randint(self, a, b):
  58.         return a + int(self.random() * (b + 1 - a))
  59.  
  60.     
  61.     def choice(self, seq):
  62.         return seq[int(self.random() * len(seq))]
  63.  
  64.  
  65. _inst = whrandom()
  66. seed = _inst.seed
  67. random = _inst.random
  68. uniform = _inst.uniform
  69. randint = _inst.randint
  70. choice = _inst.choice
  71.