Skip to content

Commit f01d1be

Browse files
authored
bpo-40286: Put methods in correct sections. Add security notice to use secrets for session tokens. (GH-19870)
1 parent 1e7e451 commit f01d1be

File tree

1 file changed

+15
-10
lines changed

1 file changed

+15
-10
lines changed

Doc/library/random.rst

+15-10
Original file line numberDiff line numberDiff line change
@@ -104,21 +104,16 @@ Bookkeeping functions
104104
the time :func:`getstate` was called.
105105

106106

107-
.. function:: getrandbits(k)
108-
109-
Returns a Python integer with *k* random bits. This method is supplied with
110-
the Mersenne Twister generator and some other generators may also provide it
111-
as an optional part of the API. When available, :meth:`getrandbits` enables
112-
:meth:`randrange` to handle arbitrarily large ranges.
113-
114-
.. versionchanged:: 3.9
115-
This method now accepts zero for *k*.
116-
107+
Functions for bytes
108+
-------------------
117109

118110
.. function:: randbytes(n)
119111

120112
Generate *n* random bytes.
121113

114+
This method should not be used for generating security tokens.
115+
Use :func:`secrets.token_bytes` instead.
116+
122117
.. versionadded:: 3.9
123118

124119

@@ -145,6 +140,16 @@ Functions for integers
145140
Return a random integer *N* such that ``a <= N <= b``. Alias for
146141
``randrange(a, b+1)``.
147142

143+
.. function:: getrandbits(k)
144+
145+
Returns a Python integer with *k* random bits. This method is supplied with
146+
the MersenneTwister generator and some other generators may also provide it
147+
as an optional part of the API. When available, :meth:`getrandbits` enables
148+
:meth:`randrange` to handle arbitrarily large ranges.
149+
150+
.. versionchanged:: 3.9
151+
This method now accepts zero for *k*.
152+
148153

149154
Functions for sequences
150155
-----------------------

0 commit comments

Comments
 (0)