1 |
|
|
/*************************************** |
2 |
|
|
Auteur : Pierre Aubert |
3 |
|
|
Mail : pierre.aubert@lapp.in2p3.fr |
4 |
|
|
Licence : CeCILL-C |
5 |
|
|
****************************************/ |
6 |
|
|
|
7 |
|
|
#ifndef __PHOENIX_RANDOM_IMPL_H__ |
8 |
|
|
#define __PHOENIX_RANDOM_IMPL_H__ |
9 |
|
|
|
10 |
|
|
#include "phoenix_random.h" |
11 |
|
|
|
12 |
|
|
///Set a random value between valInf and valSup |
13 |
|
|
/** @param[out] val : uniform random value between valInf and valSup |
14 |
|
|
* @param valInf : lower value of uniform randomizer |
15 |
|
|
* @param valSup : upper value of uniform randomizer |
16 |
|
|
*/ |
17 |
|
|
template<typename T> |
18 |
|
100 |
void phoenix_setRandValue(T & val, const T & valInf, const T & valSup){ |
19 |
|
100 |
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 |
|
100 |
T alea = (T)((((double)fourchette)*((double)rand()))/((double)(RAND_MAX))); |
22 |
|
100 |
val = alea + valInf; |
23 |
|
100 |
} |
24 |
|
|
|
25 |
|
|
///Get a random value between valInf and valSup |
26 |
|
|
/** @param valInf : lower value of uniform randomizer |
27 |
|
|
* @param valSup : upper value of uniform randomizer |
28 |
|
|
* @return uniform random value between valInf and valSup |
29 |
|
|
*/ |
30 |
|
|
template<typename T> |
31 |
|
100 |
T phoenix_getRandValue(const T & valInf, const T & valSup){ |
32 |
|
|
T val; |
33 |
|
100 |
phoenix_setRandValue(val, valInf, valSup); |
34 |
|
100 |
return val; |
35 |
|
|
} |
36 |
|
|
|
37 |
|
|
#endif |
38 |
|
|
|