bglibs: surfrand: Random number generator based on SURF

bglibs

Data Structures | Functions
surfrand: Random number generator based on SURF

## Data Structures
struct | surfrand

## Functions
void | surfrand_init (struct surfrand *c, const uint32 *data, unsigned words)
uint32 | surfrand_uint32 (struct surfrand *c)
double | surfrand_double (struct surfrand *c)
void | surfrand_fill (struct surfrand *c, unsigned char *buf, unsigned len)
uint32 | surfrand_uniform (struct surfrand *c, uint32 bound)

## Detailed Description

## Function Documentation

## ◆ surfrand_double()

double surfrand_double | ( | struct surfrand * | c | ) |

Output a random double precision floating-point number in the range 0-1.

This routine uses two calls to surfrand_uint32 to fill all the precision of a double precision floating-point with randomness.

References surfrand_uint32().

## ◆ surfrand_fill()

void surfrand_fill | ( | struct surfrand * | c,
|  | unsigned char * | buf,
|  | unsigned | len
| ) |  |

Fill the buffer with random data

References surfrand_uint32().

## ◆ surfrand_init()

void surfrand_init | ( | struct surfrand * | c,
|  | const uint32 * | data,
|  | unsigned | words
| ) |  |

Initialize the `surfrand` structure.

Initializes the seed in `c` from the input `data`, and sets the counter to zero. If more than `SURF_SEED_U32` bytes of input data is given, the extra data is merged into the seed. If less, the given data is repeated until the seed is filled.

The counter is treated as a giant multi-word integer, and is incremented once each time data is generated. This makes the theoretical period of this generator 8*2^32^12 or >10^116.

References counter, left, seed, and SURF_SEED_U32.

Referenced by surfrand_uniform().

## ◆ surfrand_uint32()

uint32 surfrand_uint32 | ( | struct surfrand * | c | ) |

Output an random unsigned 32-bit integer.

All the bits in the output integer are equally random.

References generated, and left.

Referenced by surfrand_double(), surfrand_fill(), and surfrand_uniform().

## ◆ surfrand_uniform()

uint32 surfrand_uniform | ( | struct surfrand * | c,
|  | uint32 | bound
| ) |  |

Generate a uniformly distributed random number less than `bound`.

The result is masked against bias by regenerating the result if it would cause bias.

References obuf_putc(), obuf_putxw(), outbuf, surfrand_init(), and surfrand_uint32().

Referenced by dns_random().