Skip to content

Commit 2a1f0ba

Browse files
committed
Add more examples
1 parent 67e0f8f commit 2a1f0ba

File tree

1 file changed

+31
-0
lines changed

1 file changed

+31
-0
lines changed

README.md

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,37 @@ int main(){
4343
}
4444
```
4545

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+
4677
To use the qrand library, simply include the header file `qrand.h`. The
4778
qrand uses VAES or AES-NI instructions to accelerate the random number
4879
generation. So it need to be compiled with either `-maes` or `-mvaes` option.

0 commit comments

Comments
 (0)