NumPy Tutorial NumPy Statistics NumPy References

NumPy - random.bytes() function



The NumPy random.bytes() function returns a string with the specified number of random bytes.

Syntax

numpy.random.bytes(length)

Parameters

length Required. Specify number of random bytes.

Return Value

Returns string of length length.

Example:

In the example below, random.bytes() function is used to create a string with the specified number of random bytes.

import numpy as np

x = np.random.bytes(10)

#displaying the content
print("x contains:", x)

The output of the above code will be:

x contains: b'\xe04\xa4N\xa3\xbe\xfds\xab\x9c'

❮ NumPy - Random

5