Implémentation du raytracing pour Global Memory/Shared Memory/Constant Memory
[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(uint seed)
25 {
26 srand(seed);
27 }
28
29 AleaTools::~AleaTools()
30 {
31 // rien
32 }
33
34 /*--------------------------------------*\
35 |* Methodes *|
36 \*-------------------------------------*/
37
38 /*----------------------*\
39 |* static *|
40 \*---------------------*/
41
42 /**
43 * in [a,b]
44 * Attention : pas thread safe
45 */
46 double AleaTools::uniformeAB(double a, double b)
47 {
48 return a + uniforme01() * (b - a);
49 }
50
51 /**
52 * in [0,1]
53 * Attention : pas thread safe
54 */
55 double AleaTools::uniforme01(void)
56 {
57 // rand in [0,RAND_MAX]
58 return rand() / (double) RAND_MAX;
59 }
60
61 /**
62 * in [a,b]
63 * Attention : pas thread safe
64 */
65 int AleaTools::uniformeAB(int a, int b)
66 {
67 // rand in [0,RAND_MAX]
68 double pente = (b-a)/(double)RAND_MAX;
69
70 return a+(int)(pente*rand());
71 }
72
73
74 /*----------------------------------------------------------------------*\
75 |* End *|
76 \*---------------------------------------------------------------------*/
77