Victor Stinner
9f5fe7910f
bpo-40286: Add randbytes() method to random.Random (GH-19527)
...
Add random.randbytes() function and random.Random.randbytes()
method to generate random bytes.
Modify secrets.token_bytes() to use SystemRandom.randbytes()
rather than calling directly os.urandom().
Rename also genrand_int32() to genrand_uint32(), since it returns an
unsigned 32-bit integer, not a signed integer.
The _random module is now built with Py_BUILD_CORE_MODULE defined.
2020-04-17 19:05:35 +02:00
Raymond Hettinger
041d8b48a2
bpo-38881: choices() raises ValueError when all weights are zero (GH-17362)
2019-11-23 02:22:13 -08:00
Raymond Hettinger
d0cdeaab76
bpo-32554: Deprecate hashing arbitrary types in random.seed() (GH-15382)
2019-08-22 09:19:36 -07:00
Serhiy Storchaka
2085bd0877
bpo-37116: Use PEP 570 syntax for positional-only parameters. (GH-13700)
2019-06-01 11:00:15 +03:00
Christian Heimes
d914596a67
bpo-36559: random module: optimize sha512 import (GH-12742)
...
The random module now prefers the lean internal _sha512 module over hashlib
for seed(version=2) to optimize import time.
Signed-off-by: Christian Heimes <christian@python.org>
2019-04-10 13:18:02 -07:00
Raymond Hettinger
5382203ae1
Convert range to repeat for choices() ( #11889 )
2019-02-16 13:30:51 -08:00
Raymond Hettinger
cfd31f0af2
Be consistent about the use of from-imports in random module (GH-11837)
...
Minor code clean-up.
2019-02-13 02:04:17 -08:00
Kumar Akshay
2433a2ab70
bpo-35782: Fix error message in randrange (GH-11620)
...
https://bugs.python.org/issue35782
2019-01-21 11:19:59 -08:00
leodema
63d152232e
bpo-30561: Sync-up expovariate() and gammavariate code (GH-1934)
2018-12-23 22:54:25 -08:00
Victor Stinner
8db5b54463
bpo-35513, unittest: TextTestRunner uses time.perf_counter() (GH-11180)
...
TextTestRunner of unittest.runner now uses time.perf_counter() rather
than time.time() to measure the execution time of a test: time.time()
can go backwards, whereas time.perf_counter() is monotonic.
Similar change made in libregrtest, pprint and random.
2018-12-17 11:30:34 +01:00
Raymond Hettinger
09473ac063
Remove unnecessary and over-restrictive type check (GH-10905)
2018-12-04 14:53:14 -08:00
Raymond Hettinger
7fc633f5a5
Add comments regarding speed/space/entropy trade-offs (GH-10885)
2018-12-04 00:13:38 -08:00
Raymond Hettinger
0a18e0510a
Hoist the float conversion out of the inner loop. (GH-10430)
...
Currently, the *n* and *total* variables get converted to floats each time they are multiplied by random(). This minor tweak does the conversion just once and gets a small speedup (approx 3%).
2018-11-09 02:39:50 -08:00
Raymond Hettinger
e69cd169af
Minor code refactoring. Compute len() one fewer times on one code path. (GH-8094)
2018-07-04 15:28:20 -07:00
Raymond Hettinger
ddf7171911
bpo-24567: Random subnormal.diff ( #7954 )
...
Handle subnormal weights for choices()
2018-06-27 01:08:31 -07:00
Serhiy Storchaka
ec1622d56c
bpo-33144: Fix choosing random.Random._randbelow implementation. (GH-6563)
...
random() takes precedence over getrandbits() if defined later
in the class tree.
2018-05-08 15:45:15 +03:00
Wolfgang Maier
ba3a87aca3
bpo-33144: random.Random and subclasses: split _randbelow implementation (GH-6291)
2018-04-17 08:16:17 -07:00
Wolfgang Maier
091e95e900
bpo-33203: Ensure random.choice always raises IndexError on empty sequence (GH-6338)
2018-04-05 08:19:44 -07:00
Raymond Hettinger
132a7d7cdb
bpo-31482: Missing bytes support for random.seed() version 1 ( #3614 )
...
bpo-31482: Missing bytes support for random.seed() version 1 #3614
2017-09-17 09:04:30 -07:00
Raymond Hettinger
f5ea83f486
random_triangular: sqrt() is more accurate than **0.5 ( #3317 )
2017-09-04 16:51:06 -07:00
leodema
9f396b605e
fix comment ( #1798 )
2017-06-04 07:41:41 +01:00
Gregory P. Smith
163468a766
bpo-16500: Don't use string constants for os.register_at_fork() behavior ( #1834 )
...
Instead use keyword only arguments to os.register_at_fork for each of the scenarios.
Updates the documentation for clarity.
2017-05-29 10:03:41 -07:00
Antoine Pitrou
346cbd351e
bpo-16500: Allow registering at-fork handlers ( #1715 )
...
* bpo-16500: Allow registering at-fork handlers
* Address Serhiy's comments
* Add doc for new C API
* Add doc for new Python-facing function
* Add NEWS entry + doc nit
2017-05-27 17:50:54 +02:00
Raymond Hettinger
bb2839b680
Issue #29055 : Suppress upstream exception for random.choice()
2016-12-27 01:06:52 -08:00
Raymond Hettinger
bf87126a63
Issue 28475: Improve error message for random.sample() with k < 0. (Contributed by Francisco Couzo).
2016-11-21 14:34:33 -08:00
Raymond Hettinger
24e4239434
Fix typos
2016-11-13 00:42:56 -05:00
Raymond Hettinger
8567e58ae3
Minor code beautification
2016-11-01 22:23:11 -07:00
Raymond Hettinger
30d00e54dd
Issue #18844 : Make the various ways for specifing weights produce the same results.
2016-10-29 16:55:36 -07:00
Raymond Hettinger
9016f2864a
Issue #18844 : Make the number of selections a keyword-only argument for random.choices().
2016-09-26 21:45:57 -07:00
Raymond Hettinger
28aa4a0684
Rename weighted_choices() to just choices()
2016-09-07 00:08:44 -07:00
Raymond Hettinger
e8f1e002c6
Issue #18844 : Add random.weighted_choices()
2016-09-06 17:15:29 -07:00
Victor Stinner
e66987e626
os.urandom() now blocks on Linux
...
Issue #27776 : The os.urandom() function does now block on Linux 3.17 and newer
until the system urandom entropy pool is initialized to increase the security.
This change is part of the PEP 524.
2016-09-06 16:33:52 -07:00
Raymond Hettinger
6579502c7e
Merge
2016-09-04 11:17:48 -07:00
Raymond Hettinger
16eb827b33
Improve docs for random.seed()
2016-09-04 11:17:28 -07:00
Raymond Hettinger
2f9cc7ab0c
Minor beautification (turn nested-if into a conjunction).
2016-08-31 23:00:32 -07:00
Raymond Hettinger
112835cb3e
Merge
2016-08-31 15:01:28 -07:00
Raymond Hettinger
c7bab7cbf5
Issue #27706 : Fix regression in random.seed(somestr, version=1)
2016-08-31 15:01:08 -07:00
Raymond Hettinger
650c1c9ddd
Minor beautification
2016-06-25 05:36:42 +03:00
Martin Panter
e26da7c03a
Issue #27171 : Fix typos in documentation, comments, and test function names
2016-06-02 10:07:09 +00:00
Raymond Hettinger
d58a0b6876
merge
2014-05-25 17:28:38 -07:00
Raymond Hettinger
978c6abced
Issue 13355: Make random.triangular degrade gracefully when low == high.
2014-05-25 17:25:27 -07:00
Raymond Hettinger
1f54814094
Improve readability
2014-05-19 20:21:43 +01:00
Raymond Hettinger
23042cda40
Issue #21470 : Do a better job seeding the random number generator
...
to fully cover its state space.
2014-05-13 22:13:40 -07:00
Christian Heimes
f1dc3ee16d
Issue #19218 : Rename collections.abc to _collections_abc in order to speed up interpreter start
2013-10-13 02:04:20 +02:00
Raymond Hettinger
be74a3d721
Minor clean-up of function parameters in random().
2013-10-05 21:52:06 -07:00
Raymond Hettinger
8fe47c3991
Minor clean-up of function parameters in random().
2013-10-05 21:48:21 -07:00
Raymond Hettinger
f77cdbeff7
Issue #19169 : Micro refactoring with a micro benefit for brevity and speed.
2013-10-05 17:18:36 -07:00
Senthil Kumaran
f5ce0122ce
Removing the merge conflict markers.
...
- my previous removal and hg resolve mark had still left them and hooks did not catch it too!
2013-09-12 07:06:49 -07:00
Senthil Kumaran
b4055f294e
merge from 3.3
...
Improve the docstring of random.shuffle. Inform users not to provide int arg.
Addresses issue #14927
2013-09-11 22:55:54 -07:00
Senthil Kumaran
f8ce51ab16
Improve the docstring of random.shuffle. Inform users not to provide int arg.
...
Addresses issue #14927
2013-09-11 22:54:31 -07:00
Serhiy Storchaka
46e1ce214b
Issue #18783 : Removed existing mentions of Python long type in docstrings,
...
error messages and comments.
2013-08-27 20:17:03 +03:00
Serhiy Storchaka
9594942716
Issue #18783 : Removed existing mentions of Python long type in docstrings,
...
error messages and comments.
2013-08-27 19:40:23 +03:00
Andrew Svetlov
44e33f39bf
Revert changes for #13355 by request from Raymond Hettinger
2013-04-13 18:04:19 +03:00
Andrew Svetlov
b4fd468f12
Revert changes for #13355 by request from Raymond Hettinger
2013-04-13 18:00:04 +03:00
Andrew Svetlov
730001163f
Issue #13355 : Raise ValueError on random.triangular call with invalid params.
...
Initial patch by Yuriy Senko.
2013-04-12 23:27:37 +03:00
Andrew Svetlov
a2dfc35a13
Issue #13355 : Raise ValueError on random.triangular call with invalid params.
...
Initial patch by Yuriy Senko.
2013-04-12 23:21:01 +03:00
R David Murray
d9ebf4dc1f
#17489 : Add explanatory comment that __getstate__ is not called.
...
We don't put coverage directives in the stdlib, but anyone looking at a
coverage report for Random should see the comment and understand why the lines
aren't covered.
2013-04-02 13:10:52 -04:00
Serhiy Storchaka
06e5e730dd
Issue #17141 : random.vonmisesvariate() no more hangs for large kappas.
2013-02-10 19:29:54 +02:00
Serhiy Storchaka
ac99576a8e
Issue #17141 : random.vonmisesvariate() no more hangs for large kappas.
2013-02-10 19:29:20 +02:00
Serhiy Storchaka
6c22b1d760
Issue #17141 : random.vonmisesvariate() no more hangs for large kappas.
2013-02-10 19:28:56 +02:00
Mark Dickinson
1b901baee5
Issue #17149 : merge fix from 3.3.
2013-02-10 14:17:20 +00:00
Mark Dickinson
6427358501
Issue #17149 : merge fix from 3.2.
2013-02-10 14:16:56 +00:00
Mark Dickinson
be5f91957f
Issue #17149 : Fix random.vonmisesvariate to always return results in [0, 2*math.pi].
2013-02-10 14:16:10 +00:00
Antoine Pitrou
5e3943317d
Issue #15837 : add some tests for random.shuffle().
...
Patch by Alessandro Moura.
2012-11-04 02:10:33 +01:00
Sandro Tosi
e1b22edd23
Issue #14926 : merge with 3.2
2012-06-02 19:40:20 +02:00
Sandro Tosi
29d09aa4dd
Issue #14926 : fix docstring highlight
2012-06-02 19:40:02 +02:00
Brian Curtin
4ff29db243
Merge 3.2
2011-11-11 09:41:17 -06:00
Brian Curtin
675f6b87cd
Fix #13384 . Remove __future__ import in 3.x code.
2011-11-11 09:37:25 -06:00
Raymond Hettinger
12fb2f41f0
Code simplification suggested by Sven Marnach.
2011-06-25 11:31:46 +02:00
Raymond Hettinger
5279fb99cb
Code simplification suggested by Sven Marnach.
2011-06-25 11:30:53 +02:00
Raymond Hettinger
102d874999
Sync-up minor code edits with the default branch.
2011-05-05 11:49:12 -07:00
Raymond Hettinger
7c5dc912ba
Avoid codec spelling issues by just using the utf-8 default.
2011-05-05 11:38:06 -07:00
Raymond Hettinger
f90ba8a9a2
Avoid codec spelling issues by just using the utf-8 default.
2011-05-05 11:35:50 -07:00
Ezio Melotti
0dea6484a0
#11848 : Merge with 3.2.
2011-04-15 08:27:37 +03:00
Ezio Melotti
82b0d5d144
#11848 : Merge with 3.1.
2011-04-15 08:27:00 +03:00
Ezio Melotti
20f53f1fe7
#11848 : replace dead link in random.betavariate comment.
2011-04-15 08:25:16 +03:00
Raymond Hettinger
09cbadd005
Issue 10787: Document the probability density function for random.gammavariate.
2011-03-22 15:57:03 -07:00
Raymond Hettinger
27f870982f
Issue 10787: Document the probability density function for random.gammavariate.
2011-03-22 15:56:41 -07:00
Raymond Hettinger
a8e4d6eb6e
Issue 10787: Document the probability density function for random.gammavariate.
2011-03-22 15:55:51 -07:00
Marc-André Lemburg
8f36af7a4c
Normalize the encoding names for Latin-1 and UTF-8 to
...
'latin-1' and 'utf-8'.
These are optimized in the Python Unicode implementation
to result in more direct processing, bypassing the codec
registry.
Also see issue11303.
2011-02-25 15:42:01 +00:00
Raymond Hettinger
57d1a887e7
Fix imports from collections.abc
2011-02-23 00:46:28 +00:00
Raymond Hettinger
3fcf002994
Update whatsnew. Salt the random number seed.
2010-12-08 01:13:53 +00:00
Raymond Hettinger
63b17671f0
Improve variable name (don't shadow a builtin).
2010-09-08 19:27:59 +00:00
Raymond Hettinger
8ff1099684
One more conversion from pow() to **.
2010-09-08 18:58:33 +00:00
Raymond Hettinger
183cd1fae3
* Remove dependency on binascii.hexlify by using int.from_bytes().
...
* Use the new super() with no arguments.
* Replace pow() call with the ** operator.
* Increase urandom seeding from 16 bytes to 32 bytes.
* Clean-up docstring.
2010-09-08 18:48:21 +00:00
Raymond Hettinger
e4a3e99973
In the case where only a user supplied random() method is available,
...
adopt a strategy that makes the fewest calls to random().
2010-09-08 00:30:28 +00:00
Raymond Hettinger
f015b3f5f6
Neaten-up comments and warning message.
2010-09-07 20:04:42 +00:00
Raymond Hettinger
05a505f106
Minor refactoring and cleanup. Extend looping randrange() technique to subclasses.
2010-09-07 19:19:33 +00:00
Raymond Hettinger
c585eecfb0
Fix test that depends on a particular implementation of random.choice().
2010-09-07 15:00:15 +00:00
Raymond Hettinger
dc4872eefe
Fix corner case for Random.choice() and add tests.
2010-09-07 10:06:56 +00:00
Raymond Hettinger
c324697bac
Small clean-ups.
2010-09-07 09:32:57 +00:00
Raymond Hettinger
0515661314
Issues #7889 , #9025 and #9379 : Improvements to the random module.
2010-09-07 04:44:52 +00:00
Raymond Hettinger
3051cc3a0d
Minor code cleanup
2010-09-07 00:48:40 +00:00
Raymond Hettinger
f763a728ad
Document which part of the random module module are guaranteed.
2010-09-07 00:38:15 +00:00
Mark Dickinson
884924a2fd
Issue #7435 : Remove reference to long in docstring. Thanks flox.
2009-12-05 20:32:49 +00:00
Mark Dickinson
5c2db37c20
Issue #7435 : Remove duplicate int/long tests, and other
...
references to long in py3k. Patch provided by flox.
2009-12-05 20:28:34 +00:00
Raymond Hettinger
be40db07c6
Issue 6261: Clarify behavior of random.uniform().
2009-06-11 23:12:14 +00:00
Raymond Hettinger
886687dcda
Use ABCs to validate documented restriction to Sets or Sequences.
2009-02-24 11:27:15 +00:00
Mark Dickinson
2f947369b3
Merged revisions 68378 via svnmerge from
...
svn+ssh://pythondev@svn.python.org/python/trunk
........
r68378 | mark.dickinson | 2009-01-07 17:48:33 +0000 (Wed, 07 Jan 2009) | 2 lines
Issue #4869 : clarify documentation for random.expovariate.
........
2009-01-07 17:54:07 +00:00
Benjamin Peterson
d18de0e28b
Merged revisions 65259,65263,65296,65307,65321 via svnmerge from
...
svn+ssh://pythondev@svn.python.org/python/trunk
........
r65259 | benjamin.peterson | 2008-07-27 10:22:14 -0500 (Sun, 27 Jul 2008) | 1 line
clarify Popen argument
........
r65263 | andrew.kuchling | 2008-07-28 12:04:48 -0500 (Mon, 28 Jul 2008) | 1 line
Clarify wording
........
r65296 | raymond.hettinger | 2008-07-30 02:27:30 -0500 (Wed, 30 Jul 2008) | 1 line
Neaten-up the itertools recipes.
........
r65307 | benjamin.peterson | 2008-07-30 08:46:53 -0500 (Wed, 30 Jul 2008) | 1 line
getrandombits is actually getrandbits
........
r65321 | raymond.hettinger | 2008-07-30 20:19:50 -0500 (Wed, 30 Jul 2008) | 4 lines
Alter recipe to show how to call izip_longest() with
both a keyword argument and star arguments.
........
2008-07-31 20:21:46 +00:00