Partager via


linear_congruential::operator()

Retourne une valeur aléatoire

result_type operator()();

Notes

La fonction membre génère nouvel stored_value en appliquant la relation de récurrence à l'ancienne valeur d' stored_value.

Exemple

 

// std_tr1__random__linear_congruential_operator_fn.cpp 
// compile with: /EHsc 
#include <random> 
#include <iostream> 
 
typedef std::mt19937 Myeng; 
typedef std::linear_congruential<int, 16807, 0, 
    (int)((1U << 31) - 1)> Myceng;  // same as minstd_rand0 
int main() 
    { 
    Myeng eng; 
    Myceng ceng; 
    Myceng::result_type compval = ceng(); 
 
    compval = compval;  // to quiet "unused" warnings 
 
    std::cout << "A == " << Myceng::multiplier << std::endl; 
    std::cout << "C == " << Myceng::increment << std::endl; 
    std::cout << "M == " << Myceng::modulus << 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); 
    } 
 
  

Configuration requise

en-tête : <random>

l'espace de noms : DST

Voir aussi

Référence

<random>

linear_congruential Class