Ajout des scripts pour le rendu final.
[GPU.git] / WCudaMSE / BilatTools_CPP / src / core / tools / cpp / AleaTools.cpp
1 #include <iostream>
2 #include <math.h>
3 #include <cstdlib>
4 #include <stdlib.h>
5
6 #include "AleaTools.h"
7
8 using std::cout;
9 using std::endl;
10
11 /*----------------------------------------------------------------------*\
12 |* Implementation *|
13 \*---------------------------------------------------------------------*/
14
15 /*--------------------------------------*\
16 |* Constructor *|
17 \*-------------------------------------*/
18
19 AleaTools::AleaTools()
20 {
21 srand(time(NULL));
22 }
23
24 AleaTools::~AleaTools()
25 {
26 // rien
27 }
28
29 /*--------------------------------------*\
30 |* Methodes *|
31 \*-------------------------------------*/
32
33 /*----------------------*\
34 |* static *|
35 \*---------------------*/
36
37 /**
38 * in [a,b]
39 * Attention : pas thread safe
40 */
41 double AleaTools::uniformeAB(double a, double b)
42 {
43 return a + uniforme01() * (b - a);
44 }
45
46 /**
47 * in [0,1]
48 * Attention : pas thread safe
49 */
50 double AleaTools::uniforme01(void)
51 {
52 // rand in [0,RAND_MAX]
53 return rand() / (double) RAND_MAX;
54 }
55
56 /**
57 * in [a,b]
58 * Attention : pas thread safe
59 */
60 int AleaTools::uniformeAB(int a, int b)
61 {
62 // rand in [0,RAND_MAX]
63 double pente = (b-a)/(double)RAND_MAX;
64
65 return a+(int)(pente*rand());
66 }
67
68
69 /*----------------------------------------------------------------------*\
70 |* End *|
71 \*---------------------------------------------------------------------*/
72