summaryrefslogtreecommitdiffstats
path: root/Lib/random.py
Commit message (Collapse)AuthorAgeFilesLines
* Whitespace normalization (via reindent.py).Tim Peters2005-08-261-1/+1
|
* Implement random.sample() using sets instead of dicts.Raymond Hettinger2005-08-191-9/+13
|
* SF patch #1191489: Simplify logic in random.pyRaymond Hettinger2005-04-301-9/+10
|
* Removed unused line.Raymond Hettinger2005-01-031-1/+0
|
* Use floor division operator.Raymond Hettinger2004-09-271-2/+2
|
* SF #1027105: HardwareRandom should be renamed OSRandomRaymond Hettinger2004-09-131-11/+13
| | | | | | Renamed the new generator at Trevor's recommendation. The name HardwareRandom suggested a bit more than it delivered (no radioactive decay detectors or such).
* Fulfill Martin's request to use try/except rather than a "look beforeRaymond Hettinger2004-09-051-17/+8
| | | | you leap" approach. Makes the early call to os.urandom() unnecessary.
* SF bug #1022010: Import random failsRaymond Hettinger2004-09-031-1/+2
| | | | | * trap NotImplementedError raised by os.urandom calls when not available on a particular system.
* HardwareRandom: Go back to multiplying by 2**-BPF instead of usingTim Peters2004-08-311-2/+3
| | | | | | | | | | 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.
* Take advantage of the math library's ldexp for assembling a float byRaymond Hettinger2004-08-311-5/+3
| | | | | | | 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.
* Teach the random module about os.urandom().Raymond Hettinger2004-08-301-8/+62
| | | | | * Use it for seeding when it is available. * Provide an alternate generator based on it.
* Fix typo in comment.Raymond Hettinger2004-06-071-1/+1
|
* SF bug #964230: random.choice([]) should return more intelligible exceptionRaymond Hettinger2004-06-051-1/+1
| | | | Add a comment to make the traceback less mysterious.
* Reflow long line.Jeremy Hylton2004-02-231-6/+6
|
* Whitespace normalization.Tim Peters2004-01-181-1/+1
|
* Implement and apply PEP 322, reverse iterationRaymond Hettinger2003-11-061-1/+1
|
* Minor fixup. "Random" was listed twice in __all__.Raymond Hettinger2003-10-121-2/+1
|
* SF bug #812202: randint is always evenRaymond Hettinger2003-10-051-10/+54
| | | | | | | * 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.
* SF bug #801342: Bug (documentation or real, your choice) in random.sample.Raymond Hettinger2003-09-061-0/+4
| | | | | | | | | | | | 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.
* Eliminate unnecessary eval() in testsRaymond Hettinger2003-08-301-19/+18
|
* SF bug #778964: bad seed in python 2.3 randomRaymond Hettinger2003-08-091-0/+3
| | | | | | | 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.
* Removed deprecated functionsRaymond Hettinger2003-08-051-49/+2
|
* SF bug #759889: Pickling of Random is brokenRaymond Hettinger2003-06-241-0/+3
| | | | | * Implement __reduce__() to support pickling. * Add a test case to prove a successful roundtrip through pickle.
* randrange(): Repaired my overly optimistic rewrite, and added commentsTim Peters2003-06-191-1/+13
| | | | explaining what's wrong with the two simpler variants.
* randrange(): 2.3 can no longer raises OverflowError on an int() call, soTim Peters2003-06-191-10/+1
| | | | | | 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).
* SF bug #753602: random.sample not properly documentedRaymond Hettinger2003-06-131-4/+5
| | | | | 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.
* 'sum' is no longer a good variable name. Use 'total' instead.Raymond Hettinger2003-05-241-3/+3
|
* * Migrate sample distribution test from random.py to test_random.py.Raymond Hettinger2003-01-171-5/+0
| | | | * Use Sets module to more clearly articulate a couple of tests.
* Much clearer when super() is used.Raymond Hettinger2003-01-071-5/+5
|
* Move the statistical tests for four distributions into the unittest suite.Raymond Hettinger2003-01-051-3/+0
|
* Correct long standing bugs in the methods for random distributions.Raymond Hettinger2003-01-041-4/+6
| | | | | | | 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.
* Remove the random=None nonsense from sample() before it gets set in stone.Raymond Hettinger2003-01-041-18/+11
| | | | | | | 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().
* SF patch 658251: Install a C implementation of the Mersenne Twister as theRaymond Hettinger2002-12-291-225/+178
| | | | core generator for random.py.
* Clarify and speedup test.Raymond Hettinger2002-12-071-2/+3
|
* Improve comments. Clarify docs.Raymond Hettinger2002-11-181-15/+14
| | | | | Replace "type(0)" with "int". Replace "while 1" with "while True"
* Improved clarity and thoroughness of docstring.Raymond Hettinger2002-11-131-20/+41
| | | | | | | | 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.
* Docstring typo fixAndrew M. Kuchling2002-11-131-1/+1
|
* SF patch 629637: Add sample(population, k) method to the random module.Raymond Hettinger2002-11-121-2/+56
| | | | Used for random sampling without replacement.
* SF bug 594996: OverflowError in random.randrangeTim Peters2002-08-161-4/+17
| | | | | | 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.
* Whitespace normalized.Raymond Hettinger2002-05-231-11/+11
|
* Deprecated Random.cunifvariate clearing bug 506647. Also, added docstrings.Raymond Hettinger2002-05-231-0/+81
|
* Whitespace normalization.Tim Peters2002-05-231-5/+5
|
* Use spaces, not tabs for indents.Guido van Rossum2002-05-141-4/+4
| | | | Raymond Hettinger, beware! This caused the Unix install to fail!
* Closes patch 529408 deprecating random.stdgamma().Raymond Hettinger2002-05-141-11/+35
|
* Closes SF bug 527139. Moved temp variables inside guard.Raymond Hettinger2002-05-131-7/+6
|
* random.gauss() uses a piece of hidden state used by nothing else,Tim Peters2002-05-051-1/+4
| | | | | | | | | | | 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.
* BDFL agreed with Tim: rehabilitate randint().Neal Norwitz2002-04-131-2/+0
|
* SF patch 483059: Avoid use of eval() in random.py, from Finn Bock.Tim Peters2001-11-251-6/+5
| | | | | | _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.
* Whitespace normalization.Tim Peters2001-02-151-1/+1
|
* bunch more __all__ listsSkip Montanaro2001-02-151-0/+6
| | | | | | 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)