Rietveld Code Review Tool
Help | Bug tracker | Discussion group | Source code | Sign in
(8)

Side by Side Diff: Lib/random.py

Issue 10639: reindent.py converts newlines to platform default
Patch Set: Created 8 years, 10 months ago
Left:
Right:
Use n/p to move between diff chunks; N/P to move between comments. Please Sign in to add in-line comments.
Jump to:
View unified diff | Download patch
« no previous file with comments | « Lib/_pyio.py ('k') | Lib/runpy.py » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 """Random variable generators. 1 """Random variable generators.
2 2
3 integers 3 integers
4 -------- 4 --------
5 uniform within range 5 uniform within range
6 6
7 sequences 7 sequences
8 --------- 8 ---------
9 pick random element 9 pick random element
10 pick random sample 10 pick random sample
(...skipping 384 matching lines...) Expand 10 before | Expand all | Expand 10 after
395 lambd is 1.0 divided by the desired mean. It should be 395 lambd is 1.0 divided by the desired mean. It should be
396 nonzero. (The parameter would be called "lambda", but that is 396 nonzero. (The parameter would be called "lambda", but that is
397 a reserved word in Python.) Returned values range from 0 to 397 a reserved word in Python.) Returned values range from 0 to
398 positive infinity if lambd is positive, and from negative 398 positive infinity if lambd is positive, and from negative
399 infinity to 0 if lambd is negative. 399 infinity to 0 if lambd is negative.
400 400
401 """ 401 """
402 # lambd: rate lambd = 1/mean 402 # lambd: rate lambd = 1/mean
403 # ('lambda' is a Python reserved word) 403 # ('lambda' is a Python reserved word)
404 404
405 # we use 1-random() instead of random() to preclude the 405 random = self.random
406 # possibility of taking the log of zero. 406 u = random()
407 return -_log(1.0 - self.random())/lambd 407 while u <= 1e-7:
408 u = random()
409 return -_log(u)/lambd
408 410
409 ## -------------------- von Mises distribution -------------------- 411 ## -------------------- von Mises distribution --------------------
410 412
411 def vonmisesvariate(self, mu, kappa): 413 def vonmisesvariate(self, mu, kappa):
412 """Circular data distribution. 414 """Circular data distribution.
413 415
414 mu is the mean angle, expressed in radians between 0 and 2*pi, and 416 mu is the mean angle, expressed in radians between 0 and 2*pi, and
415 kappa is the concentration parameter, which must be greater than or 417 kappa is the concentration parameter, which must be greater than or
416 equal to zero. If kappa is equal to zero, this distribution reduces 418 equal to zero. If kappa is equal to zero, this distribution reduces
417 to a uniform random angle over the range 0 to 2*pi. 419 to a uniform random angle over the range 0 to 2*pi.
(...skipping 302 matching lines...) Expand 10 before | Expand all | Expand 10 after
720 gauss = _inst.gauss 722 gauss = _inst.gauss
721 betavariate = _inst.betavariate 723 betavariate = _inst.betavariate
722 paretovariate = _inst.paretovariate 724 paretovariate = _inst.paretovariate
723 weibullvariate = _inst.weibullvariate 725 weibullvariate = _inst.weibullvariate
724 getstate = _inst.getstate 726 getstate = _inst.getstate
725 setstate = _inst.setstate 727 setstate = _inst.setstate
726 getrandbits = _inst.getrandbits 728 getrandbits = _inst.getrandbits
727 729
728 if __name__ == '__main__': 730 if __name__ == '__main__':
729 _test() 731 _test()
OLDNEW
« no previous file with comments | « Lib/_pyio.py ('k') | Lib/runpy.py » ('j') | no next file with comments »

RSS Feeds Recent Issues | This issue
This is Rietveld 894c83f36cb7+