Loading...
Searching...
No Matches
lfg.h File Reference
`#include <stdint.h>`

Go to the source code of this file.

## Data Structures

struct | AVLFG
| Context structure for the Lagged Fibonacci PRNG. More...

## Functions

void | av_lfg_init (AVLFG *c, unsigned int seed)
int | av_lfg_init_from_data (AVLFG *c, const uint8_t *data, unsigned int length)
| Seed the state of the ALFG using binary data.
static unsigned int | av_lfg_get (AVLFG *c)
| Get the next random unsigned 32-bit number using an ALFG.
static unsigned int | av_mlfg_get (AVLFG *c)
| Get the next random unsigned 32-bit number using a MLFG.
void | av_bmg_get (AVLFG *lfg, double out[2])
| Get the next two numbers generated by a Box-Muller Gaussian generator using the random numbers issued by lfg.

## Function Documentation

## av_lfg_init()

void av_lfg_init | ( | AVLFG * | c,
|  | unsigned int | seed
| ) |  |

## av_lfg_init_from_data()

int av_lfg_init_from_data | ( | AVLFG * | c,
|  | const uint8_t * | data,
|  | unsigned int | length
| ) |  |

Seed the state of the ALFG using binary data.

Returns
  0 on success, negative value (AVERROR) on failure.

## av_lfg_get()

static unsigned int av_lfg_get | ( | AVLFG * | c | ) |

inline static

Get the next random unsigned 32-bit number using an ALFG.

Please also consider a simple LCG like state= state*1664525+1013904223, it may be good enough and faster for your specific use case.

Definition at line 53 of file lfg.h.

## av_mlfg_get()

static unsigned int av_mlfg_get | ( | AVLFG * | c | ) |

inline static

Get the next random unsigned 32-bit number using a MLFG.

Please also consider av_lfg_get() above, it is faster.

Definition at line 64 of file lfg.h.

## av_bmg_get()

void av_bmg_get | ( | AVLFG * | lfg,
|  | double | out[2]
| ) |  |

Get the next two numbers generated by a Box-Muller Gaussian generator using the random numbers issued by lfg.

Parameters

  lfg | pointer to the contex structure
  out | array where the two generated numbers are placed