| Elektra 0.11.0

Functions
kdbrand.h File Reference

Defines for Rand. More...

`#include <stdint.h>`

## Functions
void | elektraRand (int32_t *seed)
| Non cryptographic pseudo random number generator.
int32_t | elektraRandGetInitSeed (void)
| Random initial seed generator.

## Detailed Description

Defines for Rand.

Copyright
  BSD License (see doc/COPYING or https://www.libelektra.org)

## Function Documentation

## ◆ elektraRand()

void elektraRand | ( | int32_t * | seed | ) |

Non cryptographic pseudo random number generator.

By Ray Gardner www8.cs.umu.se/~isak/snippets/rg_rand.c

based on "Random Number Generators: Good Ones Are Hard to Find", S.K. Park and K.W. Miller, Communications of the ACM 31:10 (Oct 1988), and "Two Fast Implementations of the 'Minimal Standard' Random Number Generator", David G. Carta, Comm. ACM 33, 1 (Jan 1990), p. 87-88

linear congruential generator f(z) = 16807 z mod (2 ** 31 - 1)

uses L. Schrage's method to avoid overflow problems

Make sure the initial seed is: 0 < seed < ELEKTRARANDMAX

Parameters

  seed | a pointer to the seed

## ◆ elektraRandGetInitSeed()

int32_t elektraRandGetInitSeed | ( | void |  | ) |

Random initial seed generator.

Generates a random initial seed for the `elektraRand (...)` function. Two invocations in the same second return the same random initial seed, due to the usage of `time (0)`.

Return values

  random | initial seed