Was this page helpful?
Your feedback about this content is important. Let us know what you think.
Additional feedback?
1500 characters remaining
Export (0) Print
Expand All
Important This document may not represent best practices for current development, links to downloads and other resources may no longer be valid. Current recommended version can be found here.

discard_block::operator()

Returns a random value.

result_type operator()();

The member function returns the next value in the sequence.

 

// std_tr1__random__discard_block_operator_fn.cpp 
// compile with: /EHsc 
#include <random> 
#include <iostream> 
 
typedef std::tr1::mt19937 Myeng; 
typedef std::tr1::discard_block<Myeng, 2, 1> Myceng; 
int main() 
    { 
    Myeng eng; 
    Myceng ceng; 
    const Myceng::base_type& base = ceng.base(); // get base engine 
    Myceng::result_type compval = ceng(); 
 
    compval = compval;  // to quiet "unused" warnings 
    base.min(); 
 
    std::cout << "P == " << Myceng::block_size << std::endl; 
    std::cout << "R == " << Myceng::used_block << 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 
 
    return (0); 
    } 
 
P == 2 R == 1 min == 0 max == 4294967295 a random value == 3499211612 a random value == 3890346734 a random value == 545404204

Header: <random>

Namespace: std::tr1

Community Additions

ADD
Show:
© 2015 Microsoft