diff options
Diffstat (limited to 'docs/random-numbers.rst')
| -rw-r--r-- | docs/random-numbers.rst | 15 |
1 files changed, 14 insertions, 1 deletions
diff --git a/docs/random-numbers.rst b/docs/random-numbers.rst index 8b119a3e..c6acd5b1 100644 --- a/docs/random-numbers.rst +++ b/docs/random-numbers.rst @@ -21,4 +21,17 @@ you can obtain them with: This will use ``/dev/urandom`` on UNIX platforms, and ``CryptGenRandom`` on Windows. -.. _`always use your operating system's provided random number generator`: http://sockpuppet.org/blog/2014/02/25/safely-generate-random-numbers/ +If you need your random number as an integer (for example, for +:meth:`~cryptography.x509.CertificateBuilder.serial_number`), you can use +``int.from_bytes`` to convert the result of ``os.urandom``: + +.. code-block:: pycon + + >>> serial = int.from_bytes(os.urandom(20), byteorder="big") + +Starting with Python 3.6 the `standard library includes`_ the ``secrets`` +module, which can be used for generating cryptographically secure random +numbers, with specific helpers for text-based formats. + +.. _`always use your operating system's provided random number generator`: https://sockpuppet.org/blog/2014/02/25/safely-generate-random-numbers/ +.. _`standard library includes`: https://docs.python.org/3/library/secrets.html |
