Export (0) Print
Expand All

subtract_with_carry_01::seed

Seeds the engine.

template<class Gen>
    void seed(Gen& gen);
void seed(result_type x0 = 19780503UL);

Gen

The type of the seed generator.

gen

The seed generator.

x0

The seed value.

Precondition: 0 < x0

The first seed function generates long_lag historical values from the values of type unsigned long returned by successive invocations of gen. Each historical value is generated by concatenating the low 32 bits from each of long_lag * (word_size + 31) / 32 values from the initialization sequence; the resulting value is then divided by 2.0word_size and the integral part discarded. Thus, each historical value is a floating-point value greater than or equal to 0.0 and less than 1.0, with word_size significant bits.

The second seed function effectively executes the following code:

    linear_congruential<unsigned long, 40014, 0, 2147483563> gen(x0);
    seed(gen);

 

// std_tr1__random__subtract_with_carry_01_seed.cpp 
// compile with: /EHsc 
#include <random> 
#include <iostream> 
 
typedef std::mt19937 Myeng; 
typedef std::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

Community Additions

ADD
Show:
© 2014 Microsoft