Random number generation

Hardware random number generation

intdm_rng_read(structudevice *dev, void*buffer, size_tsize)

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

structdm_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

voidsrand(unsignedintseed)

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

unsignedintrand(void)

Get a 32-bit pseudo-random number

Parameters

void

no arguments

Return

next random number in the sequence

unsignedintrand_r(unsignedint*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