55 Commits

Author SHA1 Message Date
Raymond Hettinger
c601117f38 SF bug #812202: randint is always even
* Extend rangrange() to return meaningful results when the range is
  larger than 2**53.  Only applies to the MersenneTwister.  WichmannHill
  was left alone in the absence of a proof showing how multiple calls
  could be combined to produce long bit streams.

* WichmannHill was missing from __all__.
2003-10-05 23:35:38 +00:00
Raymond Hettinger
07759e3786 Set the warnings stacklevel to two. 2003-09-08 19:15:43 +00:00
Raymond Hettinger
0b0aae087a SF bug #801342: Bug (documentation or real, your choice) in random.sample.
random.sample() uses one of two algorithms depending on the ratio of the
sample size to the population size.  One of the algorithms accepted any
iterable population argument so long as it defined __len__().  The other
had a stronger requirement that the population argument be indexable.

While it met the documentation specifications which insisted that the
population argument be a sequence, it made random.sample() less usable
with sets.  So, the second algorithm was modified to coerce non-indexable
iterables and dictionaries into a tuple before proceeding.
2003-09-05 21:40:30 +00:00
Raymond Hettinger
8cf915e9fb SF bug #778964: bad seed in python 2.3 random
The default seed is time.time().
Multiplied by 256 before truncating so that fractional seconds are used.
This way, two consequetive calls to random.seed() are much more likely
to produce different sequences.
2003-08-09 18:20:16 +00:00
Raymond Hettinger
5f078ff7f0 SF bug #759889: Pickling of Random is broken
* Implement __reduce__() to support pickling.
* Add a test case to prove a successful roundtrip through pickle.
2003-06-24 20:29:04 +00:00
Tim Peters
76ca1d428f randrange(): Repaired my overly optimistic rewrite, and added comments
explaining what's wrong with the two simpler variants.
2003-06-19 03:46:46 +00:00
Tim Peters
afb8979771 randrange(): 2.3 can no longer raises OverflowError on an int() call, so
some of this code because useless, and (worse) could return a long
instead of int (in Zope that's important, because a long can't be used
as a key in an IOBTree or IIBTree).
2003-06-19 03:23:06 +00:00
Raymond Hettinger
fdbe5223b7 SF bug #753602: random.sample not properly documented
The docs were fine but the "int=int" in the function call was both
ugly and confusing.  Moved it inside the body of the function definition.
2003-06-13 07:01:51 +00:00
Raymond Hettinger
b98154e424 'sum' is no longer a good variable name. Use 'total' instead. 2003-05-24 17:26:02 +00:00
Raymond Hettinger
7b0cf76b72 * Migrate sample distribution test from random.py to test_random.py.
* Use Sets module to more clearly articulate a couple of tests.
2003-01-17 17:23:23 +00:00
Raymond Hettinger
145a4a0f10 Much clearer when super() is used. 2003-01-07 10:25:55 +00:00
Raymond Hettinger
3dd990c53a Move the statistical tests for four distributions into the unittest suite. 2003-01-05 09:20:06 +00:00
Raymond Hettinger
73ced7ee99 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.

Will backport.
2003-01-04 09:26:32 +00:00
Raymond Hettinger
8b9aa8dbba Remove the random=None nonsense from sample() before it gets set in stone.
It was once available so that faster generators could be substituted.  Now,
that is less necessary and preferrably done via subclassing.

Also, clarified and shortened the comments for sample().
2003-01-04 05:20:33 +00:00
Raymond Hettinger
40f6217092 SF patch 658251: Install a C implementation of the Mersenne Twister as the
core generator for random.py.
2002-12-29 23:03:38 +00:00
Raymond Hettinger
c1ac194e94 Clarify and speedup test. 2002-12-07 09:25:05 +00:00
Raymond Hettinger
311f419628 Improve comments. Clarify docs.
Replace "type(0)" with "int".
Replace "while 1" with "while True"
2002-11-18 09:01:24 +00:00
Raymond Hettinger
c0b4034b81 Improved clarity and thoroughness of docstring.
Added design notes in comments.
Used better variable names.
Eliminated the unsavory "pool[-k:]" which was an aspiring bug (for k==0).
Used if/else to show the two algorithms in parallel style.
Added one more test assertion.
2002-11-13 15:26:37 +00:00
Andrew M. Kuchling
ea002a1aff Docstring typo fix 2002-11-13 13:25:46 +00:00
Raymond Hettinger
f24eb35d18 SF patch 629637: Add sample(population, k) method to the random module.
Used for random sampling without replacement.
2002-11-12 17:41:57 +00:00
Tim Peters
9146f27b77 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-08-16 03:41:39 +00:00
Raymond Hettinger
ef4d4bdc3c Whitespace normalized. 2002-05-23 23:58:17 +00:00
Raymond Hettinger
c32f0336e0 Deprecated Random.cunifvariate clearing bug 506647. Also, added docstrings. 2002-05-23 19:44:49 +00:00
Tim Peters
8ac1495a6a Whitespace normalization. 2002-05-23 15:15:30 +00:00
Guido van Rossum
570764ddce Use spaces, not tabs for indents.
Raymond Hettinger, beware!  This caused the Unix install to fail!
2002-05-14 14:08:12 +00:00