Commit Graph

34 Commits

Author SHA1 Message Date
Raymond Hettinger
63b5156e6e Correct long standing bugs in the methods for random distributions.
The range of u=random() is [0,1), so log(u) and 1/x can fail.
Fix by setting u=1-random() or by reselecting for a usable value.
2003-01-04 09:30:32 +00:00
Raymond Hettinger
67fe68ec65 Backport 1.33 (omitting the deprecation warning but keeping the deprecation
comment):

Deprecated Random.cunifvariate clearing bug 506647.
Also, added docstrings.
2002-10-05 14:42:52 +00:00
Raymond Hettinger
07c0e6771d Backport:
SF bug 594996:  OverflowError in random.randrange
Loosened the acceptable 'start' and 'stop' arguments so that any
Python (bounded) ints can be used.  So, e.g., randrange(-sys.maxint-1,
sys.maxint) no longer blows up.
2002-09-23 14:52:40 +00:00
Raymond Hettinger
070884c76a Whitespace normalization and backport:
random.gauss() uses a piece of hidden state used by nothing else,
and the .seed() and .whseed() methods failed to reset it.  In other
words, setting the seed didn't completely determine the sequence of
results produced by random.gauss().  It does now.  Programs repeatedly
mixing calls to a seed method with calls to gauss() may see different
results now.

Bugfix candidate (random.gauss() has always been broken in this way),
despite that it may change results.
2002-09-23 14:48:16 +00:00
Guido van Rossum
91dfd45350 Use spaces, not tabs for indents.
Raymond Hettinger, beware!  This caused the Unix install to fail!
2002-05-14 14:07:12 +00:00
Raymond Hettinger
695c737b16 Closes patch 529408 deprecating random.stdgamma(). 2002-05-14 06:56:27 +00:00
Raymond Hettinger
c28e1f8fdb Closes SF bug 527139. Moved temp variables inside guard. 2002-05-13 23:43:06 +00:00
Anthony Baxter
0e654222e7 backport nnorwitz's patch:
BDFL agreed with Tim: rehabilitate randint().
2002-04-18 05:00:45 +00:00
Tim Peters
dc47a89ff1 SF patch 483059: Avoid use of eval() in random.py, from Finn Bock.
_verify():  Pass in the values of globals insted of eval()ing their
names.  The use of eval() was obscure and unnecessary, and the patch
claimed random.py couldn't be used in Jython applets because of it.
2001-11-25 21:12:43 +00:00
Tim Peters
0e6d213177 Whitespace normalization. 2001-02-15 23:56:39 +00:00
Skip Montanaro
0de65807e6 bunch more __all__ lists
also modified check_all function to suppress all warnings since they aren't
relevant to what this test is doing (allows quiet checking of regsub, for
instance)
2001-02-15 22:15:14 +00:00
Tim Peters
bcd725fc45 Repaired a docstring. 2001-02-01 10:06:53 +00:00
Tim Peters
0de88fc4b1 Change random.seed() so that it can get at the full range of possible
internal states.  Put the old .seed() (which could only get at about
the square root of the # of possibilities) under the new name .whseed(),
for bit-level compatibility with older versions.  This occurred to me
while reviewing effbot's book (he found himself stumbling over .seed()
more than once there ...).
2001-02-01 04:59:18 +00:00
Tim Peters
715c4c412b New comment block to Clarify a subtlety. 2001-01-26 22:56:56 +00:00
Tim Peters
e360d9507a The combo of getstate/setstate/jumpahead is very powerful, but needs
examples to flesh it out for the uninitiated.  Here they are.
2001-01-26 10:00:39 +00:00
Tim Peters
85e2e4742d SF bug 130030: Claim of bad betavariate algorithm. 2001-01-26 06:49:56 +00:00
Tim Peters
cd80410854 Cosmetic changes after some sleep; no change in semantics. 2001-01-25 20:25:57 +00:00
Tim Peters
d52269bfd0 Fix bugs introduced by rewrite (in particular, time-based initialization
got broken).  Also added new method .jumpahead(N).  This finally gives us
a semi-decent answer to how Python's RNGs can be used safely and efficiently
in multithreaded programs (although it requires the user to use the new
machinery!).
2001-01-25 06:23:18 +00:00
Tim Peters
d7b5e88e8e Reworked random.py so that it no longer depends on, and offers all the
functionality of, whrandom.py.  Also closes all the "XXX" todos in
random.py.  New frequently-requested functions/methods getstate() and
setstate().  All exported functions are now bound methods of a hidden
instance.  Killed all unintended exports.  Updated the docs.
FRED:  The more I fiddle the docs, the less I understand the exact
intended use of the \var, \code, \method tags.  Please review critically.
GUIDO:  See email.  I updated NEWS as if whrandom were deprecated; I
think it should be.
2001-01-25 03:36:26 +00:00
Tim Peters
0c9886d589 Whitespace normalization. 2001-01-15 01:18:21 +00:00
Tim Peters
c1d65c34cf Repair senseless random.seed docstring (reported on c.l.py). 2000-09-16 04:02:48 +00:00
Guido van Rossum
e7b146fb3b The third and final doc-string sweep by Ka-Ping Yee.
The attached patches update the standard library so that all modules
have docstrings beginning with one-line summaries.

A new docstring was added to formatter.  The docstring for os.py
was updated to mention nt, os2, ce in addition to posix, dos, mac.
2000-02-04 15:28:42 +00:00
Guido van Rossum
6c395ba316 Add Tim Peters' shuffle() algorithm. 1999-08-18 13:53:28 +00:00
Guido van Rossum
3357561476 Added randrange to list of exported functions. 1998-07-31 13:40:05 +00:00
Guido van Rossum
d03e1197cb Make gauss() semi-thread-safe. It can still give duplicate results,
but it can no longer raise an exception when called by several threads
simultaneously.
1998-05-29 17:51:31 +00:00