Commit Graph

99 Commits

Author SHA1 Message Date
Raymond Hettinger 92df7529cb Issue 13355: Make random.triangular degrade gracefully when low == high. 2014-05-25 17:40:25 -07:00
Raymond Hettinger ddb39e799d Issue #21470: Do a better job seeding the random number generator
to fully cover its state space.
2014-05-13 22:09:23 -07:00
Raymond Hettinger 4c150e0bd2 Improve the default seeding in random module to use 32 bytes of entropy when available. 2014-03-08 09:56:08 -08:00
Raymond Hettinger 8dc1692337 Issue 14927: Minor clean-up of function parameters in random(). 2013-10-05 21:34:48 -07:00
Senthil Kumaran 37851d0e55 Improve the docstring of random.shuffle. Inform users not to provide int arg.
Addresses issue #14927
2013-09-11 22:52:58 -07:00
Andrew Svetlov 75f1fc27c3 Revert changes for #13355 by request from Raymond Hettinger 2013-04-13 18:05:44 +03:00
Andrew Svetlov b6cdae3db4 Issue #13355: Raise ValueError on random.triangular call with invalid params.
Initial patch by Yuriy Senko.
2013-04-12 23:39:33 +03:00
Serhiy Storchaka 65d56390bb Issue #17141: random.vonmisesvariate() no more hangs for large kappas. 2013-02-10 19:27:37 +02:00
Mark Dickinson 9aaeb5e0c8 Issue #17149: Fix random.vonmisesvariate to always return results in [0, 2*math.pi]. 2013-02-10 14:13:40 +00:00
Raymond Hettinger cba87311d2 Code simplification suggested by Sven Marnach. 2011-06-25 11:24:35 +02:00
Raymond Hettinger 22d8f7b9b8 Minor code cleanup. 2011-05-18 17:28:50 -05:00
Ezio Melotti 1bb18cc39e #11848: replace dead link in random.betavariate comment. 2011-04-15 08:25:16 +03:00
Raymond Hettinger 405a4717e1 Issue 10787: Document the probability density function for random.gammavariate. 2011-03-22 15:52:46 -07:00
Raymond Hettinger ffd2a4215a Issue 9816: Random.jumpahead(n) didn't work well for small values of n. 2010-09-10 10:47:22 +00:00
Raymond Hettinger 34e0de135d Remove outdated XXX comment. Mapping support was removed for 3.x. 2010-09-06 22:54:24 +00:00
Raymond Hettinger 2c0cdca564 Issue 6261: Clarify behavior of random.uniform(). 2009-06-11 23:14:53 +00:00
Mark Dickinson e6dc53120d Issue #4869: clarify documentation for random.expovariate. 2009-01-07 17:48:33 +00:00
Benjamin Peterson f2eb2b44fc getrandombits is actually getrandbits 2008-07-30 13:46:53 +00:00
Raymond Hettinger c4f7bab0a0 Adopt Nick's suggestion for useful default arguments.
Clean-up floating point issues by adding true division and float constants.
2008-03-23 19:37:53 +00:00
Raymond Hettinger bbc50eafe5 Issue 1681432: Add triangular distribution the random module. 2008-03-23 13:32:32 +00:00
Martin v. Löwis 6b449f4f2b Issue #1727780: Support loading pickles of random.Random objects created
on 32-bit systems on 64-bit systems, and vice versa. As a consequence
of the change, Random pickles created by Python 2.6 cannot be loaded
in Python 2.5.
2007-12-03 19:20:02 +00:00
Raymond Hettinger 1b0ce85271 SF# 1635892: Fix docs for betavariate's input parameters . 2007-01-19 18:07:18 +00:00
Raymond Hettinger 94547f7646 Bug #1590891: random.randrange don't return correct value for big number
Needs to be backported.
2006-12-20 06:42:06 +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
Raymond Hettinger 3081d59f92 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 successive calls to random.seed() are much more likely
to produce different sequences.
2003-08-09 18:30:57 +00:00
Raymond Hettinger f8a52d38ad Removed deprecated functions 2003-08-05 12:23:19 +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