diff options
author | Paul Kehrer <paul.l.kehrer@gmail.com> | 2015-08-08 18:42:14 -0500 |
---|---|---|
committer | Paul Kehrer <paul.l.kehrer@gmail.com> | 2015-08-08 18:42:14 -0500 |
commit | 4a4bd3ad448ffbc5adc5e94262b3a727be85f88c (patch) | |
tree | 7c419b2453800298bbf36768ff0812bf2155fe22 /docs | |
parent | abaf0494aaa18486b135ea542a3349830a92cc1f (diff) | |
parent | 4c360e4aa9b52a5d3bf2a1b95d405acdc8377750 (diff) | |
download | cryptography-4a4bd3ad448ffbc5adc5e94262b3a727be85f88c.tar.gz cryptography-4a4bd3ad448ffbc5adc5e94262b3a727be85f88c.tar.bz2 cryptography-4a4bd3ad448ffbc5adc5e94262b3a727be85f88c.zip |
Merge pull request #2228 from alex/rand-int
Document how to get a random number as an integer, fixes #2190
Diffstat (limited to 'docs')
-rw-r--r-- | docs/random-numbers.rst | 8 |
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/ |