Home | History | Annotate | Download | only in python2.7

Lines Matching defs:Random

0 """Random variable generators.
9 pick random element
10 pick random sample
11 generate random permutation
37 * The random() method is implemented in C, executes in a single Python step,
51 __all__ = ["Random","seed","random","uniform","randint","choice","sample",
72 class Random(_random.Random):
73 """Random number generator base class used by bound module functions.
75 Used to instantiate instances of Random to get generators that don't
77 a different instance of Random for each thread, and using the jumpahead()
81 Class Random can also be subclassed if you want to use a different basic
83 methods: random(), seed(), getstate(), setstate() and jumpahead().
94 Optional argument x controls seeding, as for Random.seed().
116 super(Random, self).seed(a)
121 return self.VERSION, super(Random, self).getstate(), self.gauss_next
128 super(Random, self).setstate(internalstate)
139 super(Random, self).setstate(internalstate)
142 "Random.setstate() of version %s" %
155 super(Random, self).jumpahead(n)
175 """Choose a random item from range(start, stop[, step]).
191 return int(self.random() * istart)
201 # int(istart + self.random()*width)
204 # -2.0 to 0.0 exclusive on both ends (ignoring that random()
207 # istart + int(self.random()*width)
215 return int(istart + int(self.random()*width))
235 return istart + istep*int(self.random() * n)
238 """Return random integer in range [a, b], including both end points.
245 """Return a random int in the range [0,n)
256 # Only call self.getrandbits if the original random() builtin method
259 if type(self.random) is _BuiltinMethod or type(getrandbits) is _Method:
266 _warn("Underlying random() generator does not supply \n"
268 return int(self.random() * n)
273 """Choose a random element from a non-empty sequence."""
274 return seq[int(self.random() * len(seq))] # raises IndexError if seq is empty
276 def shuffle(self, x, random=None, int=int):
277 """x, random=random.random -> shuffle list x in place; return None.
279 Optional arg random is a 0-argument function returning a random
280 float in [0.0, 1.0); by default, the standard random.random.
283 if random is None:
284 random = self.random
287 j = int(random() * (i+1))
291 """Chooses k unique random elements from a population sequence.
295 in selection order so that all sub-slices will also be valid random
321 random = self.random
332 j = _int(random() * (n-i))
340 j = _int(random() * n)
342 j = _int(random() * n)
356 "Get a random number in the range [a, b) or [a, b] depending on rounding."
357 return a + (b-a) * self.random()
370 u = self.random()
389 # A.J. and Monahan, J.F., "Computer generation of random
393 random = self.random
395 u1 = random()
396 u2 = 1.0 - random()
430 # we use 1-random() instead of random() to preclude the
432 return -_log(1.0 - self.random())/lambd
442 to a uniform random angle over the range 0 to 2*pi.
447 # if kappa = 0 generate uniform random angle
456 random = self.random
458 return TWOPI * random()
464 u1 = random()
468 u2 = random()
474 u3 = random()
504 random = self.random
516 u1 = random()
519 u2 = 1.0 - random()
529 u = random()
531 u = random()
539 u = random()
546 u1 = random()
584 random = self.random
588 x2pi = random() * TWOPI
589 g2rad = _sqrt(-2.0 * _log(1.0 - random()))
631 u = 1.0 - self.random()
644 u = 1.0 - self.random()
649 class WichmannHill(Random):
684 def random(self):
685 """Get the next random number in the range [0.0, 1.0)."""
687 # Wichman-Hill random number generator.
691 # An efficient and portable pseudo-random number generator
726 "Random.setstate() of version %s" %
730 """Act as if n calls to random() were made, but quickly.
735 consume no more than a million random numbers, create two Random
797 ## --------------- Operating System Random Source ------------------
799 class SystemRandom(Random):
800 """Alternate random number generator using sources provided
807 def random(self):
808 """Get the next random number in the range [0.0, 1.0)."""
812 """getrandbits(k) -> x. Generates a long int with k random bits."""
822 "Stub method. Not used for a system random number generator."
827 "Method should not be called for a system random number generator."
856 _test_generator(N, random, ())
877 # instantiate their own Random() instance.
879 _inst = Random()
881 random = _inst.random