blob: aa89c8e41bca1412f6ce99985f9922f5f89572d9 [file] [log] [blame]
Alex Gaynor2a70f912014-02-06 09:47:07 -08001Random number generation
2========================
3
4When generating random data for use in cryptographic operations, such as an
5initialization vector for encryption in
6:class:`~cryptography.hazmat.primitives.ciphers.modes.CBC` mode, you do not
7want to use the standard :mod:`random` module APIs. This is because they do not
8provide a cryptographically secure random number generator, resulting in
9various security issues in different algorithms.
10
11Therefore, it is our recommendation to always use your operating system's
12provided random number generator, which is available as ``os.urandom()``. For
13example, if you need 16 bytes of random data for an initialization vector, you
14can obtain them with:
15
16.. doctest::
17
18 >>> import os
19 >>> os.urandom(16)
20 '...'