aboutsummaryrefslogtreecommitdiffstats
path: root/docs/random-numbers.rst
diff options
context:
space:
mode:
authorAlex Gaynor <alex.gaynor@gmail.com>2015-08-08 18:18:09 -0400
committerAlex Gaynor <alex.gaynor@gmail.com>2015-08-08 18:18:09 -0400
commit4c360e4aa9b52a5d3bf2a1b95d405acdc8377750 (patch)
treeff8d792e954b710f25ec485c77d1b72751e33297 /docs/random-numbers.rst
parent7a108629d3358f5f07ddb7a454276e8616aa5e70 (diff)
downloadcryptography-4c360e4aa9b52a5d3bf2a1b95d405acdc8377750.tar.gz
cryptography-4c360e4aa9b52a5d3bf2a1b95d405acdc8377750.tar.bz2
cryptography-4c360e4aa9b52a5d3bf2a1b95d405acdc8377750.zip
Document how to get a random number as an integer, fixes #2190
Diffstat (limited to 'docs/random-numbers.rst')
-rw-r--r--docs/random-numbers.rst8
1 files changed, 8 insertions, 0 deletions
diff --git a/docs/random-numbers.rst b/docs/random-numbers.rst
index 8b119a3e..5f94bf13 100644
--- a/docs/random-numbers.rst
+++ b/docs/random-numbers.rst
@@ -21,4 +21,12 @@ you can obtain them with:
This will use ``/dev/urandom`` on UNIX platforms, and ``CryptGenRandom`` on
Windows.
+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")
+
.. _`always use your operating system's provided random number generator`: http://sockpuppet.org/blog/2014/02/25/safely-generate-random-numbers/