Export (0) Print
Expand All

subtract_with_carry_01::operator()

Returns a random value.

result_type operator()();

The member function generates the next value in the pseudo-random sequence by applying the recurrence relation to the stored historical values, stores the generated value, and returns it.

 

// std_tr1__random__subtract_with_carry_01_operator_fn.cpp 
// compile with: /EHsc 
#include <random> 
#include <iostream> 
 
typedef std::tr1::mt19937 Myeng; 
typedef std::tr1::subtract_with_carry_01<float, 24, 10, 24> Myceng; 
int main() 
    { 
    Myeng eng; 
    Myceng ceng; 
    Myceng::result_type compval = ceng(); 
 
    compval = compval;  // to quiet "unused" warnings 
 
    std::cout << "W == " << Myceng::word_size << std::endl; 
    std::cout << "S == " << Myceng::short_lag << std::endl; 
    std::cout << "R == " << Myceng::long_lag << std::endl; 
 
    std::cout << "min == " << ceng.min() << std::endl; 
    std::cout << "max == " << ceng.max() << std::endl; 
 
    ceng.seed(); // reseed base engine 
    std::cout << "a random value == " << ceng() << std::endl; 
    std::cout << "a random value == " << ceng() << std::endl; 
    std::cout << "a random value == " << ceng() << std::endl; 
 
    Myceng ceng2(eng); // construct with generator 
    ceng2.seed(eng);  // seed with generator 
 
    Myceng ceng3(5UL);  // construct with unsigned long seed 
    ceng3.seed(5UL);  // seed with unsigned long 
 
    return (0); 
    } 
 
W == 24 S == 10 R == 24 min == 0 max == 1 a random value == 0.896411 a random value == 0.972982 a random value == 0.851362

Header: <random>

Namespace: std::tr1

Community Additions

ADD
Show:
© 2014 Microsoft