|
reSIProcate/rutil
9694
|
#include <cstdlib>#include <iostream>#include <set>#include "rutil/Data.hxx"#include "rutil/Random.hxx"
Go to the source code of this file.
Functions | |
| int | main (int argc, char **argv) |
| int main | ( | int | argc, |
| char ** | argv | ||
| ) |
Definition at line 11 of file testRandomHex.cxx.
{
int runs = 1000;
int length = 8;
if(argc == 3)
{
runs = atoi(argv[1]);
length = atoi(argv[2]);
}
//Random::initialize();
if (runs <= 0 || length <= 0)
{
cerr << "usage: testRandomHex number_of_tries string_length" << endl
<< "number_of_tries and string_length must be a positive integers." << endl;
exit(-1);
}
cerr << "Generating " << runs << " random " << length << " byte strings and checking for uniqueness." << endl;
set<Data> randomDatas;
for (int i = 0; i < runs; i++)
{
Data foo = Random::getRandomHex(length/2);
cerr << foo << endl;
if (randomDatas.insert(foo).second == false)
{
cerr << "RandomHex produced a duplicate" << length << "byte string after " << i << " runs. " << endl;
exit(-1);
}
}
cerr << endl << "Now doing crypto random" << endl;
for (int i = 0; i < runs; i++)
{
Data foo = Random::getCryptoRandomHex(length/2);
cerr << foo << endl;
if (randomDatas.insert(foo).second == false)
{
cerr << "RandomHex produced a duplicate" << length << "byte string after " << i << " runs. " << endl;
exit(-1);
}
}
cerr << "Success." << endl;
return 0;
}
1.7.5.1