Hello peeps, I'm at the snake tutorial right now, wish i had more time for tuts but for now i have one question.
i see chilli did something i can't fully understand and i wish you could help me.
when initializing the rng constructor
rng(std::random_device()()) he used 2 of "()", my question is why.
rng is from "std::mt19937 rng;"
Noob question
Re: Noob question
The first () constructs the random_device object, and the second () calls the function operator (the generator function) on that object.
Chili
-
- Posts: 4373
- Joined: February 28th, 2013, 3:23 am
- Location: Oklahoma, United States
Re: Noob question
If I do this:
I get the error "Function returning function is not allowed".
However, if I do it in a class initializer list:
Everything builds fine.
If you create a temporary random number generator in a function, you must use braces to construct the random_device and parentheses to call the operator() ( generate function ).
Code: Select all
std::mt19937 rng( std::random_device()( ) );
However, if I do it in a class initializer list:
Code: Select all
class MyClass
{
public:
MyClass()
:
rng( std::random_device()( ) )
{}
private:
std::mt19937 rng;
};
If you create a temporary random number generator in a function, you must use braces to construct the random_device and parentheses to call the operator() ( generate function ).
Code: Select all
std::mt19937 rng( std::random_device{}( ) );
If you think paging some data from disk into RAM is slow, try paging it into a simian cerebrum over a pair of optical nerves. - gameprogrammingpatterns.com
Re: Noob question
Think that's because compiler thinks you're declaring a function.
Computer too slow? Consider running a VM on your toaster.