Compartilhar via


subtract_with_carry::subtract_with_carry

Constructs the engine.

subtract_with_carry();
explicit subtract_with_carry(unsigned long x0 = default_seed);
template<class Gen>
   subtract_with_carry(Gen& gen);
subtract_with_carry(const subtract_with_carry& right);
subtract_with_carry(subtract_with_carry& right);

Parameters

  • x0
    The seed value.

  • Gen
    The type of the seed generator.

  • gen
    The seed generator.

  • right
    A subtract_with_carry object.

Remarks

The first constructor constructs a subtract_with_carry object and initializes it by calling seed().

The second constructor constructs a subtract_with_carry object and initializes it by calling seed(x0).

The third constructor constructs a subtract_with_carry object and initializes it by calling seed(gen).

The fourth and fifth constructors construct a subtract_with_carry object by copying a subtract_with_carry object.

Example

 

// std_tr1__random__subtract_with_carry_construct.cpp 
// compile with: /EHsc 
#include <random> 
#include <iostream> 
 
typedef std::mt19937 Myeng; 
typedef std::subtract_with_carry<unsigned int, 1 << 24, 
    10, 24> Myceng; 
int main() 
    { 
    Myeng eng; 
    Myceng ceng; 
    Myceng::result_type compval = ceng(); 
 
    compval = compval;  // to quiet "unused" warnings 
 
    std::cout << "M == " << Myceng::modulus << 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); 
    } 
 
M == 16777216
S == 10
R == 24
min == 0
max == 16777215
a random value == 15039276
a random value == 16323925
a random value == 14283486

Requirements

Header: <random>

Namespace: std

See Also

Reference

<random>

subtract_with_carry Class

Other Resources

<random> Members