embedded system library for e-puck  1.0.1
A redesigned API library for the e-puck robot platform
 All Data Structures Files Functions Variables Enumerations Enumerator Modules Pages
Functions
el_random.h File Reference
#include "el_common.h"

Go to the source code of this file.

Functions

void el_random_set_seed (int seed)
 set seed of the random generator module More...
 
void el_random_reset_seed (void)
 reset the random seed to default value
 
el_uint16 el_random_get_seed (void)
 get seed of the current random sequence More...
 
el_uint16 el_random_uint16 (void)
 returning a random unsigned short int in [0,65535] More...
 
el_uint32 el_random_uint32 (void)
 returning a random unsigned long int in [0,2^32 - 1] More...
 
el_int16 el_random_int (el_int16 min, el_int16 max)
 returning a random int in [min,max] More...
 
el_bool el_random_rate (el_uint16 num, el_uint16 den)
 returning true at a probability of (num/den) More...
 

Detailed Description

Author
Jianing Chen

Function Documentation

void el_random_set_seed ( int  seed)

set seed of the random generator module

Parameters
seedthe random seed

In a Pseudo random generator like this, the random seed defines the sequence of values generated. Nth values of the random generators using the same seed are same.

el_uint16 el_random_get_seed ( void  )

get seed of the current random sequence

Returns
the random seed
el_uint16 el_random_uint16 ( void  )

returning a random unsigned short int in [0,65535]

Returns
the unsigned short int
el_uint32 el_random_uint32 ( void  )

returning a random unsigned long int in [0,2^32 - 1]

Returns
the unsigned long int
el_int16 el_random_int ( el_int16  min,
el_int16  max 
)

returning a random int in [min,max]

Returns
the int
el_bool el_random_rate ( el_uint16  num,
el_uint16  den 
)

returning true at a probability of (num/den)

Parameters
numnumerator of the probability
dendenominator of the probability
Returns
a Boolean result

This function has a (num/den) chance of returning true. It can be used in probability based branch. For example:

1 ...
2 if(el_random_rate(1,5)){
3 
4  // do A (20 percent of chance)
5 
6 }else{
7 
8  // do B (80 percent of chance)
9 
10 }
11 ...