I was converting some code to practice a random number generator method I was reading about online. Strange thing is, It doesn't seem to work with numbers over 99. Even if I change the initial high number to 200 or above, it still hits a limit at 99 if the input number is 100+. I know I 'must be missing something rather obvious. Can anyone help me by pointing it out?
Rasta,
please clean up your code and make it as short as possible to still contain the issue.
In its current state the code will not compile. There is
- an erroneous f in the 1st while loop,
- a missing ; in the second while loop,
- the initialization of 'guess' is commented out before it is used.
Once this is done, I can look at it again. But there is also a chance it will help you sort out what is wrong as well.
Vitaliy
Sorry for the unclean code, to be honest it was late, I was tired, and it was compiling for me (Well sort of) so I assumed it was fine.
Now that I look at it with fresh eyes, there is no reason it should have compiled. Yesterday, I had just installed the latest version of CodeBlocks and was trying to use the new c++ 11 capabilities.
I now realize there is something wrong with my compiler or the way I have it set up.
error: unrecognized command line option "-std=c++11"
So I figured out that I was having compiler issues, I re-installed and now everything is working great - rather it didn't compile as it was posted, just as it shouldn't have.
Cleaned it up, now its compiling, but I am getting a runtime error now.
"Terminate called after throwing an instance of 'std::runtime_error'
what(): random_device::random_device(const std::string&)
I think my problem is that I don't understand how this method generates random numbers. I read that it - Obtains a random number from Hardware, then you seed the generator, define a range, and than generate the numbers.
Works as posted.
I've seen that exception thrown when attempting to use std::random_device on ideone.com, where hardware access is blocked for security reasons.
If you have the same problem, you may have to fall back to the age-old time(NULL) for the seed.