/[resiprocate]/main/rutil/test/testRandomHex.cxx
ViewVC logotype

Contents of /main/rutil/test/testRandomHex.cxx

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1294 - (show annotations) (download)
Mon Mar 24 22:42:27 2003 UTC (16 years, 8 months ago) by jason
Original Path: main/sip/resiprocate/test/testRandomHex.cxx
File size: 1508 byte(s)
change from sip2 to resiprocate

1
2 #include <iostream>
3 #include <set>
4
5 #include "resiprocate/util/Data.hxx"
6 #include "resiprocate/util/Random.hxx"
7
8 using namespace std;
9 using namespace Vocal2;
10
11 int main(int argc, char** argv)
12 {
13 if(argc != 3)
14 {
15 cerr << "usage: testRandomHex number_of_tries string_length" << endl;
16 exit(-1);
17 }
18
19 int runs = atoi(argv[1]);
20 int length = atoi(argv[2]);
21
22 Random::initialize();
23
24
25 if (runs <= 0 || length <= 0)
26 {
27 cerr << "usage: testRandomHex number_of_tries string_length" << endl
28 << "number_of_tries and string_length must be a positive integers." << endl;
29 exit(-1);
30 }
31
32 cerr << "Generating " << runs << " random " << length << " byte strings and checking for uniqueness." << endl;
33
34 set<Data> randomDatas;
35
36 for (int i = 0; i < runs; i++)
37 {
38 Data foo = Random::getRandomHex(length/2);
39 cerr << foo << endl;
40 if (randomDatas.insert(foo).second == false)
41 {
42 cerr << "RandomHex produced a duplicate" << length << "byte string after " << i << " runs. " << endl;
43 exit(-1);
44 }
45 }
46
47 cerr << endl << "Now doing crypto random" << endl;
48
49 for (int i = 0; i < runs; i++)
50 {
51 Data foo = Random::getCryptoRandomHex(length/2);
52 cerr << foo << endl;
53 if (randomDatas.insert(foo).second == false)
54 {
55 cerr << "RandomHex produced a duplicate" << length << "byte string after " << i << " runs. " << endl;
56 exit(-1);
57 }
58 }
59
60 cerr << "Success." << endl;
61 }
62
63

webmaster AT resiprocate DOT org
ViewVC Help
Powered by ViewVC 1.1.27