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

Annotation of /main/sip/resiprocate/test/testRandomHex.cxx

Parent Directory Parent Directory | Revision Log Revision Log


Revision 712 - (hide annotations) (download)
Sat Nov 23 22:06:27 2002 UTC (17 years, 2 months ago) by fluffy
File size: 1490 byte(s)
fixed Random Number stuff

1 derekm 485
2     #include <iostream>
3     #include <set>
4    
5 jason 537 #include "sip2/util/Data.hxx"
6 fluffy 712 #include "sip2/util/Random.hxx"
7 derekm 485
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 fluffy 712 Random::initialize();
23    
24    
25 derekm 485 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 fluffy 712 Data foo = Random::getRandomHex(length);
39     cerr << foo << endl;
40 derekm 485 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 fluffy 712
47     cerr << endl << "Now doing crypto random" << endl;
48    
49     for (int i = 0; i < runs; i++)
50     {
51     Data foo = Random::getCryptoRandomHex(length);
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 derekm 485 cerr << "Success." << endl;
61     }
62    
63    

webmaster AT resiprocate DOT org
ViewVC Help
Powered by ViewVC 1.1.27