简体   繁体   中英

What's the difference between using an mt19937_64 instance with or without the function call operator ()?

I created an mt19937_64 instance with a seed like so;

std::mt19937_64 mt_engine{9156}

What's the difference between using the instance like:

mt_engine()

or just

mt_engine

in code. And when should I use either?

I can't seem to find any material that explains this precisely. All I find on this stuff is either filled with unnecessary information I don't need or math I do not understand at the moment so be of help?

Edit: I'd include code of the two instances

#include <random>
#include <iostream>
int main() {
    std::mt19937_64 mt_engine{91586}
    std::cout << mt_engine(); // outputs just one long number
    std::cout << mt_engine; //outputs sort of like an array of long numbers
}

What's the difference between the two use cases? Thanks.

mt_engine is an expression of type std::mt19937_64 . You use it to refer to the generator.

mt_engine() is an expression of type std::uint_fast64_t . You use it when you want a random number from the generator.

What's the difference between the two use cases?

std::cout << mt_engine() generates a random number, and outputs the number.

std::cout << mt_engine outputs the internal state of mt_engine

See operator<<,>>(std::mersenne_twister_engine)

Serializes the internal state of the pseudo-random number engine e as a sequence of decimal numbers separated by one or more spaces, and inserts it to the stream ost. The fill character and the formatting flags of the stream are ignored and unaffected.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM