Jump to content

  • Log In with Google      Sign In   
  • Create Account

Mingw g++ 4.6.2 crash


Old topic!

Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.


  • You cannot reply to this topic
4 replies to this topic

#1   Members   

2833
Like
0Likes
Like

Posted 23 March 2012 - 09:06 AM

Some time ago i have downloaded CodeBlocks with Ming32 package, since it has outdated g++ version i have downloaded it separately (4.6.2) and changed compiler/linker paths acordingly, and also added new PATH path into environment variables to Mingw/bin.
Then recently tried some example code from cppreference:
#include <random>
#include <iostream>

int main()
{
    std::random_device rd;
    std::mt19937 gen(rd());
    std::uniform_int_distribution<> dis(1, 6);
    for(int n=0; n<10; ++n)
	    std::cout << dis(gen) << ' ';
    std::cout << '\n';
    return 0;
}
and it crashed:

terminate called after throwing an instance of 'std::runtime_error'
what(): random_device::random_device(const std::string&)

This application has requested the Runtime to terminate it in an unusual way.
Please contact the application's support team for more information.


Got same message if i compile it from command line its same as from IDE.

Tried it on VS 2010 it works, tried it on Ubuntu 11.10 g++ 4.6.2 thru Virtual machine also works.

Any idea?

#2   Members   

154
Like
1Likes
Like

Posted 23 March 2012 - 10:46 AM

MinGW does not fully support C++11 features yet. This may be one of those items that isn't quite there.

#3   Members   

8306
Like
1Likes
Like

Posted 23 March 2012 - 11:29 AM

That error means a failure to open the file "/dev/urandom". My guess is that such a device is not supported under MinGW. If there is in fact a valid hardware entropy source available in Windows and presented as a file node, pass the name of that to the std::random_device constructor, otherwise you will not be able to use the hardware entropy source feature of the standard library.

You could, instead, use good old std::time() to initialize your PRNG engine. It's pretty portable and good enough for non-cryptographic purposes.
Stephen M. Webb
Professional Free Software Developer

#4   Members   

2833
Like
0Likes
Like

Posted 23 March 2012 - 11:43 AM

Thanks. I thought it was somehow my fault.

@Bregma
Like this?
std::mt19937 gen(static_cast<unsigned int>(std::time(nullptr)));
...


Is this suitable for game projects puproses, when it is possibly called multiple times in "tight" loops?

#5   Members   

20255
Like
1Likes
Like

Posted 23 March 2012 - 11:45 AM

Seeding a pseudo-random number generator in a tight loop is never a good option. You should seed it once and use it many times.




Old topic!

Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.