| Commit message (Collapse) | Author | Age | Files | Lines |
| |
|
|
|
|
| |
Add a comment to make the traceback less mysterious.
|
| |
|
| |
|
| |
|
| |
|
|
|
|
|
|
|
| |
* 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.
|
|
|
|
|
|
|
|
|
|
|
|
| |
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.
|
| |
|
|
|
|
|
|
|
| |
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.
|
| |
|
|
|
|
|
| |
* Implement __reduce__() to support pickling.
* Add a test case to prove a successful roundtrip through pickle.
|
|
|
|
| |
explaining what's wrong with the two simpler variants.
|
|
|
|
|
|
| |
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).
|
|
|
|
|
| |
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.
|
| |
|
|
|
|
| |
* Use Sets module to more clearly articulate a couple of tests.
|
| |
|
| |
|
|
|
|
|
|
|
| |
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.
|
|
|
|
|
|
|
| |
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().
|
|
|
|
| |
core generator for random.py.
|
| |
|
|
|
|
|
| |
Replace "type(0)" with "int".
Replace "while 1" with "while True"
|
|
|
|
|
|
|
|
| |
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.
|
| |
|
|
|
|
| |
Used for random sampling without replacement.
|
|
|
|
|
|
| |
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.
|
| |
|
| |
|
| |
|
|
|
|
| |
Raymond Hettinger, beware! This caused the Unix install to fail!
|
| |
|
| |
|
|
|
|
|
|
|
|
|
|
|
| |
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.
|
| |
|
|
|
|
|
|
| |
_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.
|
| |
|
|
|
|
|
|
| |
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)
|
| |
|
|
|
|
|
|
|
|
| |
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 ...).
|
| |
|
|
|
|
| |
examples to flesh it out for the uninitiated. Here they are.
|
| |
|
| |
|
|
|
|
|
|
|
| |
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!).
|
|
|
|
|
|
|
|
|
|
|
| |
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.
|
| |
|
| |
|
|
|
|
|
|
|
|
| |
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.
|