Random functions¶
random_u32()
¶
Generate a random 32-bit unsigned integer.
Returns:
-
int–A random 32-bit unsigned integer between 0 and 0xffffffff (included).
random_uniform(upper_bound)
¶
randomize_buffer(buf)
¶
Fill a buffer with random bytes.
Parameters:
-
buf(Buffer) –A buffer to fill with random bytes. The buffer must be writable.
gen_random_buffer(size)
¶
shuffle_buffer(buf)
¶
Shuffle a buffer in place.
Parameters:
-
buf(Buffer) –A buffer to shuffle. The buffer must be writable.
pad(buf, blocksize=8192)
¶
Pad a buffer to a multiple of the specified block size.
Parameters:
-
buf(Buffer) –A buffer to pad.
-
blocksize(int, default:8192) –The block size to pad to (default is 8192).
Returns:
-
bytes–A bytes object containing the padded buffer.
Raises:
-
ValueError–If blocksize is invalid
unpad(buf, blocksize=8192)
¶
Unpad a buffer that was padded to a multiple of the specified block size.
Parameters:
-
buf(Buffer) –A padded buffer to unpad.
-
blocksize(int, default:8192) –The block size that was used for padding (default is 8192).
Returns:
-
bytes–A bytes object containing the unpadded buffer.
Raises:
-
ValueError–If the buffer is not padded correctly or if blocksize is invalid.