PhoenixMock  1.8.7
Tools to split/merge/print mock used in Phoenix
phoenix_random.h File Reference
#include <stdlib.h>
#include <iostream>
#include "phoenix_random_impl.h"
+ Include dependency graph for phoenix_random.h:
+ This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Functions

template<typename T >
phoenix_getRandValue (const T &valInf, const T &valSup)
 Get a random value between valInf and valSup. More...
 
unsigned int phoenix_initRandom ()
 Set the random seed. More...
 
template<typename T >
void phoenix_setRandValue (T &val, const T &valInf, const T &valSup)
 Set a random value between valInf and valSup. More...
 

Function Documentation

◆ phoenix_getRandValue()

template<typename T >
T phoenix_getRandValue ( const T &  valInf,
const T &  valSup 
)

Get a random value between valInf and valSup.

Parameters
valInf: lower value of uniform randomizer
valSup: upper value of uniform randomizer
Returns
uniform random value between valInf and valSup

Definition at line 31 of file phoenix_random_impl.h.

31  {
32  T val;
33  phoenix_setRandValue(val, valInf, valSup);
34  return val;
35 }

References phoenix_setRandValue().

Referenced by testRandom().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ phoenix_initRandom()

unsigned int phoenix_initRandom ( )

Set the random seed.

Returns
seed of the random function

Definition at line 13 of file phoenix_random.cpp.

13  {
14  time_t t = time(NULL);
15  srand(t);
16  return t;
17 }

Referenced by testRandom().

+ Here is the caller graph for this function:

◆ phoenix_setRandValue()

template<typename T >
void phoenix_setRandValue ( T &  val,
const T &  valInf,
const T &  valSup 
)

Set a random value between valInf and valSup.

Parameters
[out]val: uniform random value between valInf and valSup
valInf: lower value of uniform randomizer
valSup: upper value of uniform randomizer

Definition at line 18 of file phoenix_random_impl.h.

18  {
19  T fourchette = valSup - valInf;
20  //l'utilisation de double est nécéssaire pour permettre de bons tirages aléatoires avec des nombres entiers
21  T alea = (T)((((double)fourchette)*((double)rand()))/((double)(RAND_MAX)));
22  val = alea + valInf;
23 }

Referenced by phoenix_getRandValue().

+ Here is the caller graph for this function:
phoenix_setRandValue
void phoenix_setRandValue(T &val, const T &valInf, const T &valSup)
Set a random value between valInf and valSup.
Definition: phoenix_random_impl.h:18