当前位置: 首页>>代码示例>>C++>>正文


C++ PRNG::set_type方法代码示例

本文整理汇总了C++中PRNG::set_type方法的典型用法代码示例。如果您正苦于以下问题:C++ PRNG::set_type方法的具体用法?C++ PRNG::set_type怎么用?C++ PRNG::set_type使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在PRNG的用法示例。


在下文中一共展示了PRNG::set_type方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。

示例1: 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;
}
开发者ID:plempert,项目名称:prnglib,代码行数:78,代码来源:test_xorgens.cpp


注:本文中的PRNG::set_type方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。