DataScript: avi.utils.rand_bytes
Note: This function is supported in Avi Vantage release 18.2.5+.
Function |
avi.utils.rand_bytes(num_bytes) |
Description |
Enables users to generate cryptographically secure random bytes of data. |
Events |
All |
Parameter |
num_bytes is an integer between 0 and 1024. |
Returns |
A string containing num_bytes random bytes of data.
Notes
- Lua defines a string as a sequence of bytes. Therefore, manipulations valid for bytes within the ASCII range are likewise valid for bytes outside the ASCII range.
- Printing these random bytes will mostly likely show unrecognizable characters.
- Alternative methods such as
math.random cannot be relied upon to return cryptographically secure random values, such as might be needed when creating UUIDs. |
Example |
Log 8 random bytes in the VS application log:
random_bytes = avi.utils.rand_bytes(8)
avi.vs.log(random_bytes)
|