本文整理汇总了C++中PRNG::set方法的典型用法代码示例。如果您正苦于以下问题:C++ PRNG::set方法的具体用法?C++ PRNG::set怎么用?C++ PRNG::set使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类PRNG
的用法示例。
在下文中一共展示了PRNG::set方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: main
int main(){
unsigned int seed_value[32];
for(int i=0; i<32; i++){
seed_value[i] = i*2; // Arbitrary seed value
}
InitWELLRNG1024a(seed_value);
PRNG* rng = PRNGFactory::generatePRNG("well");
rng->set(seed_value);
for(int i=0; i<10; i++){
double original_generator = WELLRNG1024a();
double PRNGFactory_generator = rng->get_double();
std::cout << original_generator << " " << PRNGFactory_generator << "\n";
if(original_generator != PRNGFactory_generator){
std::cout << "The streams do not match\n";
exit(0);
}
}
high_resolution_clock::time_point t1, t2;
// Measure the time it takes the original generator to produce 1 billion values
t1 = high_resolution_clock::now();
for(int i=0; i<1000000000; i++){
unsigned long original_stream = WELLRNG1024a();
}
t2 = high_resolution_clock::now();
auto duration = duration_cast<microseconds>( t2 - t1 ).count();
std::cout << "Original well generator used "<< duration << " microseconds to generate 1 billion values" << std::endl;
// Measure the time it takes the new generator to produce 1 billion values
t1 = high_resolution_clock::now();
for(int i=0; i<1000000000; i++){
unsigned long PRNG_stream = rng->get_double();
}
t2 = high_resolution_clock::now();
duration = duration_cast<microseconds>( t2 - t1 ).count();
std::cout << "PRNGFactory xorgens generator used "<< duration << " microseconds to generate 1 billion values" << std::endl;
return 0;
}
示例2: main
int main(){
int seed_value = 5; // An arbitrary seed value
xor4096i(seed_value); // Seed the original number generator
PRNG* rng = PRNGFactory::generatePRNG("xorgens"); // Seed the PRNGFactory number generator
rng->set_type("int"); // Determine whether to produce integers or doubles
rng->set(seed_value); // Set the seed value
// Test that the generators produce the same values for 100 million iterations
for(int i=0; i<5; i++){
unsigned long original_generator = xor4096i(0);
unsigned long PRNGFactory_generator = rng->get_long();
std::cout << original_generator << " " << PRNGFactory_generator << "\n";
if(original_generator != PRNGFactory_generator){
std::cout << "The streams do not match\n";
exit(0);
}
}
high_resolution_clock::time_point t1, t2;
// Measure the time it takes the original generator to produce 1 billion values
t1 = high_resolution_clock::now();
for(int i=0; i<500000000; i++){
unsigned long original_stream = xor4096i(0);
}
t2 = high_resolution_clock::now();
auto duration = duration_cast<microseconds>( t2 - t1 ).count();
std::cout << "Original xorgens generator used "<< duration/1000000.0 << " seconds to generate 500000000 values" << std::endl;
// Measure the time it takes the original generator to produce 1 billion values
t1 = high_resolution_clock::now();
for(int i=0; i<500000000; i++){
unsigned long PRNG_stream = rng->get_long();
}
t2 = high_resolution_clock::now();
duration = duration_cast<microseconds>( t2 - t1 ).count();
std::cout << "PRNGFactory xorgens generator used "<< duration/1000000.0 << " seconds to generate 500000000 values" << std::endl;
// print("Original xorgens generator:");
// // Seed integer number generator
// xor4096i(5);
// // Generator random long
// print(xor4096i(0));
// // Seed real number generator
// xor4096r(10);
// // Generator random real number
// print(xor4096r(0));
// print("PRNGFactory version:");
// // Allocate memory for a new xorgens RNG.
// PRNG* rng = PRNGFactory::generatePRNG("xorgens");
// // Set type to generate longs
// rng->set_type("int");
// rng->set(5);
// print(rng->get_long());
// print(rng->get_long());
// PRNG* rng_i = PRNGFactory::generatePRNG("xorgens");
// // Set type to generate longs
// rng_i->set_type("int");
// rng_i->set(5);
// print(rng->get_long());
// print(rng_i->get_long());
// PRNG* rng_r = PRNGFactory::generatePRNG("xorgens");
// // Set type to generate longs
// rng_r->set_type("real");
// rng_r->set(10);
// print(rng_r->get_double());
return 0;
}