Commit graph

147 commits

Author SHA1 Message Date
Serhiy Storchaka
c55512311b
gh-135376: Fix and improve test_random (GH-135377)
* Remove duplicated code. Tests for Random and SystemRandom now share
  the code.
* Move implementation agnostic tests that was only run for SystemRandom,
  so they are now run for Random too.
* Add tests for __index__() support.
* Add tests for randint().
2025-06-18 18:26:01 +03:00
Serhiy Storchaka
5ae669fc4e
gh-135326: Test support of __index__ in random.getrandbits() (#135356)
Some checks are pending
Tests / CIFuzz (push) Blocked by required conditions
Tests / All required checks pass (push) Blocked by required conditions
Lint / lint (push) Waiting to run
mypy / Run mypy on Lib/_pyrepl (push) Waiting to run
mypy / Run mypy on Lib/test/libregrtest (push) Waiting to run
mypy / Run mypy on Lib/tomllib (push) Waiting to run
mypy / Run mypy on Tools/build (push) Waiting to run
mypy / Run mypy on Tools/cases_generator (push) Waiting to run
mypy / Run mypy on Tools/clinic (push) Waiting to run
mypy / Run mypy on Tools/jit (push) Waiting to run
mypy / Run mypy on Tools/peg_generator (push) Waiting to run
Tests / Change detection (push) Waiting to run
Tests / Docs (push) Blocked by required conditions
Tests / Windows MSI (push) Blocked by required conditions
Tests / Check if Autoconf files are up to date (push) Blocked by required conditions
Tests / Check if generated files are up to date (push) Blocked by required conditions
Tests / (push) Blocked by required conditions
Tests / Ubuntu SSL tests with OpenSSL (push) Blocked by required conditions
Tests / WASI (push) Blocked by required conditions
Tests / Hypothesis tests on Ubuntu (push) Blocked by required conditions
Tests / Address sanitizer (push) Blocked by required conditions
Tests / Cross build Linux (push) Blocked by required conditions
2025-06-10 18:51:08 -07:00
Serhiy Storchaka
68784fed78
gh-133489: Remove size restrictions on getrandbits() and randbytes() (GH-133658)
random.getrandbits() can now generate more that 2**31 bits.
random.randbytes() can now generate more that 256 MiB.
2025-05-31 11:23:01 +03:00
Serhiy Storchaka
2602d8ae98
gh-71339: Use new assertion methods in tests (GH-129046) 2025-05-22 13:17:22 +03:00
Hugo van Kemenade
4ac916ae33
gh-130645: Add color to stdlib argparse CLIs (gh-133380) 2025-05-05 19:46:46 +02:00
Raymond Hettinger
286c517db0
gh-130285: Fix handling of zero or empty counts in random.sample() (gh-130291) 2025-02-21 11:33:10 -06:00
Anders Kaseorg
a362c41bc9
gh-123968: Fix lower bound for python -m random --float (#123971) 2024-09-12 16:54:18 +03:00
Hugo van Kemenade
3b32575ed6
gh-118131: Command-line interface for the random module (#118132) 2024-05-05 06:30:03 +00:00
Tian Gao
dc0adb44d8
Add extra tests for random.binomialvariate (gh-112325) 2023-11-23 12:31:03 -06:00
Raymond Hettinger
9a68ff12c3
GH-100805: Support numpy.array() in random.choice(). (GH-100830) 2023-01-08 13:40:35 -06:00
Raymond Hettinger
b430399d41
GH-100234: Set a default value for random.expovariate() (GH-100235) 2022-12-15 12:40:45 -06:00
Raymond Hettinger
ed06ec1ab8
GH-81620: Add random.binomialvariate() (GH-94719) 2022-07-13 09:46:04 -05:00
Raymond Hettinger
68fec31364
gh-86388 Remove deprecated behaviors in randrange() (#92677) 2022-05-11 23:54:51 -05:00
Zackery Spytz
08ec80113b
bpo-46737: Add default arguments to random.gauss and normalvariate (GH-31360) 2022-02-15 17:12:15 -06:00
Miro Hrončok
6baa98e538
bpo-46624: Defer to 3.12: "Remove deprecated support for non-integer values" (GH-31098) 2022-02-03 07:48:13 -06:00
Christian Heimes
91e33ac3d0
bpo-40280: Add requires_fork test helper (GH-30622) 2022-01-16 22:52:43 +01:00
Raymond Hettinger
3fee7776e6
Move error test to the function that needs it. Improve error message. (GH-30008) 2021-12-09 20:24:50 -06:00
Serhiy Storchaka
574241632b
bpo-42222: Improve tests for invalid argument types in randrange() (GH-29021) 2021-10-19 20:40:30 +02:00
Raymond Hettinger
5afa0a4112
bpo-42222: Remove deprecated support for non-integer values (GH-28983) 2021-10-16 10:16:53 -05:00
Serhiy Storchaka
a6a2065881
bpo-44260: Do not read system entropy without need in Random() (GH-26455) 2021-05-31 23:24:20 +03:00
Raymond Hettinger
70a071d9e1
bpo-40465: Remove random module features deprecated in 3.9 (GH-25874) 2021-05-04 10:55:40 +02:00
Raymond Hettinger
b05352e4c2
bpo-44018: random.seed() no longer mutates its inputs (GH-25856) 2021-05-03 16:11:35 -07:00
Serhiy Storchaka
f066bd94b9
bpo-37319: Improve documentation, code and tests of randrange. (GH-19112) 2021-01-25 23:02:04 +02:00
jonanifranco
f7b5bacd7a
bpo-42944 Fix Random.sample when counts is not None (GH-24235) 2021-01-18 10:04:29 -08:00
Raymond Hettinger
768fa145cf
bpo-42772: Step argument ignored when stop is None. (GH-24018) 2021-01-02 10:24:51 -08:00
Raymond Hettinger
a9621bb301
bpo-42222: Modernize integer test/conversion in randrange() (#23064) 2020-12-28 11:10:34 -08:00
AMIR
b8fde8b541
bpo-42008: Fix internal _random.Random() seeding for the one argument case (GH-22668) 2020-12-21 15:45:50 -08:00
masklinn
1e27b57dbc
bpo-42470: Do not warn on sequences which are also sets in random.sample() (GH-23665) 2020-12-18 20:33:36 -08:00
Ram Rachum
b0dfc75816
bpo-41773: Raise exception for non-finite weights in random.choices(). (GH-22441) 2020-09-28 18:32:10 -07:00
Dong-hee Na
6989af0bc7
bpo-41052: Opt out serialization/deserialization for _random.Random (GH-21002) 2020-06-21 18:44:58 +09:00
Raymond Hettinger
81a5fc38e8
bpo-40541: Add optional *counts* parameter to random.sample() (GH-19970) 2020-05-08 07:53:15 -07:00
Raymond Hettinger
190fac99c5
bpo-40465: Deprecate the optional argument to random.shuffle(). (#19867) 2020-05-02 16:45:32 -07:00
Raymond Hettinger
4168f1e460
Simplify choice()'s interaction with the private _randbelow() method (GH-19831) 2020-05-01 10:34:19 -07:00
Raymond Hettinger
4fe002045f
bpo-40325: Deprecate set object support in random.sample() (GH-19591) 2020-04-19 00:36:42 -07:00
Serhiy Storchaka
223221b290
bpo-40286: Makes simpler the relation between randbytes() and getrandbits() (GH-19574) 2020-04-17 23:51:28 +03:00
Antoine Pitrou
75a3378810
bpo-40282: Allow random.getrandbits(0) (GH-19539) 2020-04-17 19:32:14 +02:00
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
Victor Stinner
278c1e159c
bpo-40094: Add test.support.wait_process() (GH-19254)
Moreover, the following tests now check the child process exit code:

* test_os.PtyTests
* test_mailbox.test_lock_conflict()
* test_tempfile.test_process_awareness()
* test_uuid.testIssue8621()
* multiprocessing resource tracker tests
2020-03-31 20:08:12 +02:00
Victor Stinner
00d7cd8ab8
bpo-38075: Fix random_seed(): use PyObject_CallOneArg() (GH-18897)
Fix the random.Random.seed() method when a bool is passed as the
seed.

PyObject_Vectorcall() was misused: use PyObject_CallOneArg() instead.
2020-03-10 15:15:14 +01:00
Raymond Hettinger
041d8b48a2
bpo-38881: choices() raises ValueError when all weights are zero (GH-17362) 2019-11-23 02:22:13 -08:00
Xtreak
a06d683d7f bpo-38120: Fix DeprecationWarning in test_random for invalid type of arguments to random.seed. (GH-15987) 2019-09-12 11:13:20 +03:00
Min ho Kim
96e12d5f4f Fix typos in docs, comments and test assert messages (#14872) 2019-07-21 16:12:33 -04:00
penguindustin
9646630895 bpo-36766: Typos in docs and code comments (GH-13116) 2019-05-06 14:57:17 -04:00
Serhiy Storchaka
5b10b98247
bpo-22831: Use "with" to avoid possible fd leaks in tests (part 2). (GH-10929) 2019-03-05 10:06:26 +02:00
leodema
63d152232e bpo-30561: Sync-up expovariate() and gammavariate code (GH-1934) 2018-12-23 22:54:25 -08: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
Mike
53f7a7c281 bpo-32297: Few misspellings found in Python source code comments. (#4803)
* Fix multiple typos in code comments

* Add spacing in comments (test_logging.py, test_math.py)

* Fix spaces at the beginning of comments in test_logging.py
2017-12-14 13:04:53 +02:00