Random number generation
Hardware random number generation
-
int dm_rng_read(struct udevice *dev, void *buffer, size_t size)
read a random number seed from the rng device
Parameters
struct udevice *dev
random number generator device
void *buffer
input buffer to put the read random seed into
size_t size
number of random bytes to read
Description
The function blocks until the requested number of bytes is read.
Return
0 if OK, -ve on error
-
struct dm_rng_ops
operations for the hwrng uclass
Definition
struct dm_rng_ops {
int (*read)(struct udevice *dev, void *data, size_t max);
};
Members
read
read a random bytes
The function blocks until the requested number of bytes is read.
read.dev: random number generator device read.data: input buffer to read the random seed into read.max: number of random bytes to read read.Return: 0 if OK, -ve on error
Description
This structures contains the function implemented by a hardware random number generation device.
Pseudo random number generation
-
void srand(unsigned int seed)
Set the random-number seed value
Parameters
unsigned int seed
New seed
Description
This can be used to restart the pseudo-random-number sequence from a known point. This affects future calls to rand() to start from that point
-
unsigned int rand(void)
Get a 32-bit pseudo-random number
Parameters
void
no arguments
Return
next random number in the sequence
-
unsigned int rand_r(unsigned int *seedp)
Get a 32-bit pseudo-random number
Parameters
unsigned int *seedp
seed value to use, updated on exit
Description
This version of the function allows multiple sequences to be used at the same time, since it requires the caller to store the seed value.
Return
next random number in the sequence