source:
tests/random.c
@
2fd9f24
Last change on this file since 2fd9f24 was 73abe95, checked in by , 6 years ago | |
---|---|
|
|
File size: 1.7 KB |
Rev | Line | |
---|---|---|
[73abe95] | 1 | // |
[ed0e67a] | 2 | // Cforall Version 1.0.0 Copyright (C) 2016 University of Waterloo |
3 | // | |
4 | // The contents of this file are covered under the licence agreement in the | |
5 | // file "LICENCE" distributed with Cforall. | |
[73abe95] | 6 | // |
7 | // random.c -- | |
8 | // | |
[ed0e67a] | 9 | // Author : Peter A. Buhr |
10 | // Created On : Tue Jul 5 21:29:30 2016 | |
11 | // Last Modified By : Peter A. Buhr | |
[54aba8d] | 12 | // Last Modified On : Tue Jan 2 12:19:34 2018 |
13 | // Update Count : 19 | |
[73abe95] | 14 | // |
[5721a6d] | 15 | |
[73abe95] | 16 | #include <fstream.hfa> |
17 | #include <stdlib.hfa> // random | |
[ed0e67a] | 18 | #include <unistd.h> // getpid |
[5721a6d] | 19 | |
20 | int main() { | |
[54aba8d] | 21 | // srandom( getpid() ); // set random seed |
22 | srandom( 1003 ); // fixed seed for repeatable tests | |
[5721a6d] | 23 | |
24 | // test polymorphic calls to random and stream | |
[6c7b1e7] | 25 | char c = random(); |
[5721a6d] | 26 | sout | c | endl; |
[e672372] | 27 | c = random( 'A' ); |
28 | sout | c | endl; | |
29 | c = random( 'A', 'Z' ); | |
30 | sout | c | endl; | |
31 | ||
[6c7b1e7] | 32 | int i = random(); |
[5721a6d] | 33 | sout | i | endl; |
[e672372] | 34 | i = random( 10 ); |
35 | sout | i | endl; | |
36 | i = random( -10, 20 ); | |
37 | sout | i | endl; | |
38 | ||
[6c7b1e7] | 39 | unsigned int ui = random(); |
[5721a6d] | 40 | sout | ui | endl; |
[e672372] | 41 | ui = random( 10u ); |
42 | sout | ui | endl; | |
43 | ui = random( 10u, 20u ); | |
44 | sout | ui | endl; | |
45 | ||
[6c7b1e7] | 46 | long int li = random(); |
[5721a6d] | 47 | sout | li | endl; |
[e672372] | 48 | li = random( 10l ); |
49 | sout | li | endl; | |
50 | li = random( -10l, 20l ); | |
51 | sout | li | endl; | |
52 | ||
[6c7b1e7] | 53 | unsigned long int uli = random(); |
[5721a6d] | 54 | sout | uli | endl; |
[e672372] | 55 | uli = random( 10ul ); |
56 | sout | uli | endl; | |
57 | uli = random( 10ul, 20ul ); | |
58 | sout | uli | endl; | |
59 | ||
[6c7b1e7] | 60 | float f = random(); |
[5721a6d] | 61 | sout | f | endl; |
[e672372] | 62 | |
[6c7b1e7] | 63 | double d = random(); |
[5721a6d] | 64 | sout | d | endl; |
[e672372] | 65 | |
[6c7b1e7] | 66 | float _Complex fc = random(); |
[5721a6d] | 67 | sout | fc | endl; |
[e672372] | 68 | |
[6c7b1e7] | 69 | double _Complex dc = random(); |
[5721a6d] | 70 | sout | dc | endl; |
[e672372] | 71 | |
[6c7b1e7] | 72 | long double _Complex ldc = random(); |
[5721a6d] | 73 | sout | ldc | endl; |
74 | } // main | |
75 | ||
76 | // Local Variables: // | |
77 | // tab-width: 4 // | |
78 | // compile-command: "cfa random.c" // | |
79 | // End: // |
Note: See TracBrowser
for help on using the repository browser.