78 Commits

Author SHA1 Message Date
Raymond Hettinger
3b77d3d9a7 SF# 1635892: Fix docs for betavariate's input parameters . 2007-01-19 18:03:13 +00:00
Raymond Hettinger
5425a67331 Bug #1590891: random.randrange don't return correct value for big number 2006-12-20 07:43:59 +00:00
Tim Peters
0e1159583c shuffle() doscstring: Removed warning about sequence length
versus generator period.  While this was a real weakness of the
older WH generator for lists with just a few dozen elements,
and so could potentially bite the naive ;-), the Twister should
show excellent behavior up to at least 600 elements.

Module docstring:  reflowed some jarringly short lines.
2006-06-10 22:51:45 +00:00
Tim Peters
c17976e983 Another crack at bug #1460340: make random.sample(dict)
work, this time by ugly brute force.
2006-04-01 00:26:53 +00:00
Raymond Hettinger
3c3346daa9 SF bug #1460340: random.sample can raise KeyError
Fix the hit and miss style of testing for sets and dicts.
2006-03-29 09:13:13 +00:00
Tim Peters
9e34c04732 Whitespace normalization (via reindent.py). 2005-08-26 15:20:46 +00:00
Raymond Hettinger
91e27c253c Implement random.sample() using sets instead of dicts. 2005-08-19 01:36:35 +00:00
Raymond Hettinger
42406e6f27 SF patch #1191489: Simplify logic in random.py 2005-04-30 09:02:51 +00:00
Raymond Hettinger
362b929222 Removed unused line. 2005-01-03 07:33:16 +00:00
Raymond Hettinger
ffdb8bb99c Use floor division operator. 2004-09-27 15:29:05 +00:00
Raymond Hettinger
23f1241dc6 SF #1027105: HardwareRandom should be renamed OSRandom
Renamed the new generator at Trevor's recommendation.
The name HardwareRandom suggested a bit more than it
delivered (no radioactive decay detectors or such).
2004-09-13 22:23:21 +00:00
Raymond Hettinger
c1c43cad63 Fulfill Martin's request to use try/except rather than a "look before
you leap" approach.  Makes the early call to os.urandom() unnecessary.
2004-09-05 00:00:42 +00:00
Raymond Hettinger
bdbdfd731d SF bug #1022010: Import random fails
* trap NotImplementedError raised by os.urandom calls when not available
  on a particular system.
2004-09-03 19:09:22 +00:00
Tim Peters
7c2a85b2d4 HardwareRandom: Go back to multiplying by 2**-BPF instead of using
ldexp.  Both methods are exact, and return the same results.  Turns out
multiplication is a few (but just a few) percent faster on my box.
They're both significantly faster than using struct with a Q format
to convert bytes to a 64-bit long (struct.unpack() appears to lose due
to the tuple creation/teardown overhead), and calling _hexlify is
significantly faster than doing bytes.encode('hex').  So we appear to
have hit a local minimum (wrt speed) here.
2004-08-31 02:19:55 +00:00
Raymond Hettinger
3fa19d7ff8 Take advantage of the math library's ldexp for assembling a float by
components without division and without roundoff error for properly
sized mantissas (i.e. on systems with 53 or more mantissa bits per
float).  Eliminates the previous implementation's rounding bias as
aptly demonstrated by Tim Peters.
2004-08-31 01:05:15 +00:00
Raymond Hettinger
356a4599ac Teach the random module about os.urandom().
* Use it for seeding when it is available.
* Provide an alternate generator based on it.
2004-08-30 06:14:31 +00:00
Raymond Hettinger
5dae505bbd Fix typo in comment. 2004-06-07 02:07:15 +00:00
Raymond Hettinger
9021c95595 SF bug #964230: random.choice([]) should return more intelligible exception
Add a comment to make the traceback less mysterious.
2004-06-05 14:53:22 +00:00
Jeremy Hylton
2b55d35850 Reflow long line. 2004-02-23 17:27:57 +00:00
Tim Peters
58eb11cf62 Whitespace normalization. 2004-01-18 20:29:55 +00:00
Raymond Hettinger
85c20a41df Implement and apply PEP 322, reverse iteration 2003-11-06 14:06:48 +00:00
Raymond Hettinger
411c602349 Minor fixup. "Random" was listed twice in __all__. 2003-10-12 17:14:11 +00:00
Raymond Hettinger
2f726e9093 SF bug #812202: randint is always even
* Added C coded getrandbits(k) method that runs in linear time.
* Call the new method from randrange() for ranges >= 2**53.
* Adds a warning for generators not defining getrandbits() whenever they
  have a call to randrange() with too large of a population.
2003-10-05 09:09:15 +00:00
Raymond Hettinger
66d09f1b30 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-06 04:25:54 +00:00
Raymond Hettinger
6229713221 Eliminate unnecessary eval() in tests 2003-08-30 01:24:19 +00:00