File tree Expand file tree Collapse file tree 1 file changed +31
-0
lines changed Expand file tree Collapse file tree 1 file changed +31
-0
lines changed Original file line number Diff line number Diff line change @@ -43,6 +43,37 @@ int main(){
43
43
}
44
44
```
45
45
46
+ Or you can use the callable object as a drop in replacement for rand function:
47
+
48
+ ``` c++
49
+ #include < iostream>
50
+ #include " qrand.h"
51
+
52
+ int main (){
53
+ qrand randq;
54
+ for(int i = 0; i < 10; i++){
55
+ std::cout << randq() << " " << randq() % 100 << std::endl;
56
+ }
57
+ }
58
+ ```
59
+
60
+ There is no global state, so it's thread safe as long as it's thread local:
61
+
62
+ ``` c++
63
+ void some_thread_function (){
64
+ static thread_local qrand randq;
65
+ // call randq
66
+ }
67
+ ```
68
+
69
+ Or in OpenMP
70
+
71
+ ``` c++
72
+ extern qrand randq;
73
+ #pragma omp threadprivate(randq)
74
+ qrand randq;
75
+ ```
76
+
46
77
To use the qrand library, simply include the header file ` qrand.h ` . The
47
78
qrand uses VAES or AES-NI instructions to accelerate the random number
48
79
generation. So it need to be compiled with either ` -maes ` or ` -mvaes ` option.
You can’t perform that action at this time.
0 commit comments