Documentation>C API
Data Structures | Functions
random.h File Reference

Random number generator (Random number generator). More...

`#include "host.h"`

## Data Structures

struct | VlRand
| Random numbber generator state. More...

## Functions

void | vl_rand_permute_indexes (VlRand *self, vl_index *array, vl_size size)
| Randomly permute and array of indexes.
Setting and reading the state
void | vl_rand_init (VlRand *self)
| Initialise random number generator.
void | vl_rand_seed (VlRand *self, vl_uint32 s)
| Seed the state of the random number generator.
void | vl_rand_seed_by_array (VlRand *self, vl_uint32 const key[], vl_size keySize)
| Seed the state of the random number generator by an array.
Generate random numbers
vl_uint64 | vl_rand_uint64 (VlRand *self)
| Generate a random UINT64.
vl_int64 | vl_rand_int63 (VlRand *self)
| Generate a random INT63.
vl_uint32 | vl_rand_uint32 (VlRand *self)
| Generate a random UINT32.
vl_int32 | vl_rand_int31 (VlRand *self)
| Generate a random INT31.
double | vl_rand_real1 (VlRand *self)
| Generate a random number in [0,1].
double | vl_rand_real2 (VlRand *self)
| Generate a random number in [0,1).
double | vl_rand_real3 (VlRand *self)
| Generate a random number in (0,1).
double | vl_rand_res53 (VlRand *self)
| Generate a random number in [0,1) with 53-bit resolution.
vl_uindex | vl_rand_uindex (VlRand *self, vl_uindex range)
| Generate a random index in a given range.

## Detailed Description

Author
  Andrea Vedaldi

See also
  Random number generator

## Function Documentation

## ◆ vl_rand_init()

void vl_rand_init | ( | VlRand * | self | ) |

Parameters

  self | number generator.

## ◆ vl_rand_int31()

vl_int32 vl_rand_int31 | ( | VlRand * | self | ) |

inline

Parameters

  self | random number generator.

Returns
  a random number in [0, 0x7fffffff].

## ◆ vl_rand_int63()

vl_int64 vl_rand_int63 | ( | VlRand * | self | ) |

inline

Parameters

  self | random number generator.

Returns
  a random number in [0, 0x7fffffffffffffff].

## ◆ vl_rand_permute_indexes()

void vl_rand_permute_indexes | ( | VlRand * | self,
|  | vl_index * | array,
|  | vl_size | size )

Parameters

  self | random number generator.
  array | array of indexes.
  size | number of element in the array.

The function uses Algorithm P, also known as Knuth shuffle.

## ◆ vl_rand_real1()

double vl_rand_real1 | ( | VlRand * | self | ) |

inline

Parameters

  self | random number generator.

Returns
  a random number.

## ◆ vl_rand_real2()

double vl_rand_real2 | ( | VlRand * | self | ) |

inline

Parameters

  self | random number generator.

Returns
  a random number.

## ◆ vl_rand_real3()

double vl_rand_real3 | ( | VlRand * | self | ) |

inline

Parameters

  self | random number generator.

Returns
  a random number.

## ◆ vl_rand_res53()

double vl_rand_res53 | ( | VlRand * | self | ) |

inline

Parameters

  self | random number generator.

Returns
  a random number.

## ◆ vl_rand_seed()

void vl_rand_seed | ( | VlRand * | self,
|  | vl_uint32 | s )

Parameters

  self | random number generator.
  s | seed.

## ◆ vl_rand_seed_by_array()

void vl_rand_seed_by_array | ( | VlRand * | self,
|  | vl_uint32 const | key[],
|  | vl_size | keySize )

Parameters

  self | random number generator.
  key | array of numbers.
  keySize | length of the array.

## ◆ vl_rand_uindex()

vl_uindex vl_rand_uindex | ( | VlRand * | self,
|  | vl_uindex | range )

inline

Parameters

  self | random number generator.
  range | range.

Returns
  an index sampled uniformly at random in the interval [0, `range` - 1]

Remarks
  Currently, this function uses a simple algorithm that may yield slightly biased samples if `range` is not a power of two.

## ◆ vl_rand_uint32()

vl_uint32 vl_rand_uint32 | ( | VlRand * | self | ) |

Parameters

  self | random number generator.

Returns
  a random number in [0, 0xffffffff].

## ◆ vl_rand_uint64()

vl_uint64 vl_rand_uint64 | ( | VlRand * | self | ) |

inline

Parameters

  self | random number generator.

Returns
  a random number in [0, 0xffffffffffffffff].