1: //test_randomgenerator2.cpp
2: //A test driver for the Scobey::RandomGenerator class.
4: #include <iostream>
5: using namespace std;
7: #include "utilities.h"
8: using Scobey::RandomGenerator;
9: using Scobey::Pause;
11: int main()
12: {
13: Pause(0, "\nTesting the RandomGenerator class ..."
14: "\n\nThe first group of values shown will be the same "
15: "on each run because the\nsingle random generator used for "
16: "generating all the values is initialized\nwith a fixed "
17: "starting seed. The values shown will include: "
18: "\n- 20 integers from the range 0..9"
19: "\n- 20 integers from the range 10..15"
20: "\n- 8 real numbers from the range [0.0, 1.0)"
21: "\n- 8 real numbers from the range [1.0, 1.5)"
22: "\n- 15 strings of length 2, 3 or 4 and characters only from "
23: "the word \"dog\""
24: "\n- 15 strings of length 3 or 4, with characters only from the "
25: "words \"any\"\n and \"time\", and lying between these two "
26: "words in the dictionary sense"
27: "\n- 5 strings, all of length 6, and each one containing only "
28: "capital letters"
29: "\n- 5 strings, each having a length from the range 1..4, "
30: "and each having only\n characters from the string \"Hello, "
31: "world!\"\n");
33: cout << "\n\nAnd here are the values:\n\n";
34: RandomGenerator g(10);
35: for (int i=1; i<=20; i++) cout << g.getNext(10) << " ";
36: cout << endl;
37: for (int i=1; i<=20; i++) cout << g.getNext(10, 15) << " ";
38: cout << endl;
39: for (int i=1; i<=8; i++) cout << g.getNext(1.0) << " ";
40: cout << endl;
41: for (int i=1; i<=8; i++) cout << g.getNext(1.0, 1.5) << " ";
42: cout << endl;
43: for (int i=1; i<=15; i++) cout << g.getNext("aabbbbdog") << " ";
44: cout << endl;
45: for (int i=1; i<=15; i++) cout << g.getNext("any", "time") << " ";
46: cout << endl;
47: for (int i=1; i<=5; i++)
48: cout << g.getNextStringFromCharRange(6, 'A', 'Z') << " ";
49: cout << endl;
50: for (int i=1; i<=5; i++)
51: cout << g.getNextStringFromString(4, "Hello, world!") << " ";
52: cout << endl;
53: Pause();
55: Pause(0, "The next group of values shown will contain the same "
56: "number of the same kinds\nof values as the previous group, but "
57: "these values will be different on each\nrun because the random "
58: "generator has been reset with a random seed.\n");
60: cout << "\nHere is the second group of values:\n\n";
61: g.reset();
62: for (int i=1; i<=20; i++) cout << g.getNext(10) << " ";
63: cout << endl;
64: for (int i=1; i<=20; i++) cout << g.getNext(10, 15) << " ";
65: cout << endl;
66: for (int i=1; i<=8; i++) cout << g.getNext(1.0) << " ";
67: cout << endl;
68: for (int i=1; i<=8; i++) cout << g.getNext(1.0, 1.5) << " ";
69: cout << endl;
70: for (int i=1; i<=15; i++) cout << g.getNext("aabbbbdog") << " ";
71: cout << endl;
72: for (int i=1; i<=15; i++) cout << g.getNext("any", "time") << " ";
73: cout << endl;
74: for (int i=1; i<=5; i++)
75: cout << g.getNextStringFromCharRange(6, 'A', 'Z') << " ";
76: cout << endl;
77: for (int i=1; i<=5; i++)
78: cout << g.getNextStringFromString(4, "Hello, world!") << " ";
79: cout << endl;
80: Pause();
82: Pause(0, "The third group of values shown will contain exactly "
83: "the same values as the\nfirst group, because the same random "
84: "generator is being used and that random\ngenerator has been "
85: "reset with the same seed that was used for that first\ngroup.\n");
87: cout << "\nHere is the third group of values:\n\n";
88: g.reset(10);
89: for (int i=1; i<=20; i++) cout << g.getNext(10) << " ";
90: cout << endl;
91: for (int i=1; i<=20; i++) cout << g.getNext(10, 15) << " ";
92: cout << endl;
93: for (int i=1; i<=8; i++) cout << g.getNext(1.0) << " ";
94: cout << endl;
95: for (int i=1; i<=8; i++) cout << g.getNext(1.0, 1.5) << " ";
96: cout << endl;
97: for (int i=1; i<=15; i++) cout << g.getNext("aabbbbdog") << " ";
98: cout << endl;
99: for (int i=1; i<=15; i++) cout << g.getNext("any", "time") << " ";
100: cout << endl;
101: for (int i=1; i<=5; i++)
102: cout << g.getNextStringFromCharRange(6, 'A', 'Z') << " ";
103: cout << endl;
104: for (int i=1; i<=5; i++)
105: cout << g.getNextStringFromString(4, "Hello, world!") << " ";
106: cout << endl;
107: Pause();
109: RandomGenerator g1;
110: Pause(0, "Finally, we declare a second random generator, "
111: "initialized with a random seed,\nand generate once again, "
112: "the same number and kinds of values, which will be"
113: "\ndifferent on each run because of the random starting seed.");
115: cout << "\nHere is that final group of values:\n\n";
116: for (int i=1; i<=20; i++) cout << g1.getNext(10) << " ";
117: cout << endl;
118: for (int i=1; i<=20; i++) cout << g1.getNext(10, 15) << " ";
119: cout << endl;
120: for (int i=1; i<=8; i++) cout << g1.getNext(1.0) << " ";
121: cout << endl;
122: for (int i=1; i<=8; i++) cout << g1.getNext(1.0, 1.5) << " ";
123: cout << endl;
124: for (int i=1; i<=15; i++) cout << g1.getNext("aabbbbdog") << " ";
125: cout << endl;
126: for (int i=1; i<=15; i++) cout << g1.getNext("any", "time") << " ";
127: cout << endl;
128: for (int i=1; i<=5; i++)
129: cout << g1.getNextStringFromCharRange(6, 'A', 'Z') << " ";
130: cout << endl;
131: for (int i=1; i<=5; i++)
132: cout << g1.getNextStringFromString(4, "Hello, world!") << " ";
133: cout << endl;
134: Pause();
136: Pause(0, "No more tests to perform."
137: "\nProgram will now terminate.");
138: }