source:
src/examples/random.c
@
76c7f65e
Last change on this file since 76c7f65e was 0438091, checked in by , 8 years ago | |
---|---|
|
|
File size: 843 bytes |
Rev | Line | |
---|---|---|
[5721a6d] | 1 | extern "C" { |
2 | #include <unistd.h> // getpid | |
3 | } // extern "C" | |
4 | ||
5 | #include <fstream> | |
[bd85400] | 6 | #include <stdlib> // random |
[5721a6d] | 7 | |
8 | int main() { | |
[0438091] | 9 | rand48seed( getpid() ); // set random seed |
[5721a6d] | 10 | |
11 | // test polymorphic calls to random and stream | |
[0438091] | 12 | char c = rand48(); |
[5721a6d] | 13 | sout | c | endl; |
[0438091] | 14 | int i = rand48(); |
[5721a6d] | 15 | sout | i | endl; |
[0438091] | 16 | unsigned int ui = rand48(); |
[5721a6d] | 17 | sout | ui | endl; |
[0438091] | 18 | long int li = rand48(); |
[5721a6d] | 19 | sout | li | endl; |
[0438091] | 20 | unsigned long int uli = rand48(); |
[5721a6d] | 21 | sout | uli | endl; |
[0438091] | 22 | float f = rand48(); |
[5721a6d] | 23 | sout | f | endl; |
[0438091] | 24 | double d = rand48(); |
[5721a6d] | 25 | sout | d | endl; |
[0438091] | 26 | float _Complex fc = rand48(); |
[5721a6d] | 27 | sout | fc | endl; |
[0438091] | 28 | double _Complex dc = rand48(); |
[5721a6d] | 29 | sout | dc | endl; |
[0438091] | 30 | long double _Complex ldc = rand48(); |
[5721a6d] | 31 | sout | ldc | endl; |
32 | } // main | |
33 | ||
34 | // Local Variables: // | |
35 | // tab-width: 4 // | |
36 | // compile-command: "cfa random.c" // | |
37 | // End: // |
Note: See TracBrowser
for help on using the repository browser.