Random number generation (what's missing?)

I have tried a simple example straight off the Microsoft website Link in order to try to figure this out, but it won't compile for me.  I just want to create a uniformly distributed random number (long long).   I think I may be missing something, but I have no idea what.  

#include <random>
#include <iostream>

using namespace std;
using namespacestd::tr1;
//typedef std::tr1::random_device rd;

int main()
    random_device rd;   // non-deterministic generator
    mt19937 gen(rd());  // to seed mersenne twister.
    uniform_int_distribution<> dist(1,6); // distribute results between 1 and 6 inclusive.

    for (int i = 0; i < 5; ++i) {
        cout << dist(gen) << " "; // pass the generator to the distribution.
    cout << endl;

Open in new window

Here are the errors I am getting.
Compile errors
I would appreciate any insight.  I am using VS2008 w/SP1.

Elena QuinnAsked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

If you download a later version of VS, the program will run as a C++11 program.
Just remove the line:
using namespacestd::tr1;

Here's where you can download VS Express:

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Elena QuinnAuthor Commented:

Does that mean it doesn't work in 2008 with SP1?  When initially researching this on the Microsoft site, the <random> included 2008.  But then I read on another question somewhere that I had to install SP1.  So I did that.

I kinda need it to work with 2008, unfortunately.  The developers I am working with are only using that.  Tried to get them to switch to 2013, but no go.

Elena QuinnAuthor Commented:
BTW, I did try rand() with not much success.  The distribution is not uniform at all.  See the pic of a distribution of 1000 tries.  Distribution using rand()
Determine the Perfect Price for Your IT Services

Do you wonder if your IT business is truly profitable or if you should raise your prices? Learn how to calculate your overhead burden with our free interactive tool and use it to determine the right price for your IT services. Download your free eBook now!

In what way did you try rand(), and how did results between 1 and 6 inclusive produce that histogram?
I don't have VS 2008, but I looked up items in MSDN. <random> is defined in VS 2008, but your error indicates that uniform_int_distribution is an undeclared identifier. This identifier in <random> was included in C++11:

uniform_int_distribution is defined here in VS 2015:
and here in VS 2013:
but not in VS 2010;
and not here in VS 2008:
Prior to C++11, there was TR1 which I now read can be included in VS 2008 by installing a Feature Pack. I don't believe that SP1 and Feature Pack are the same things. Let me know whether you downloaded the Feature Pack from here:

Possibly give that a try. I am not sure whether you will have problems in VS 2008 getting the correct <random>, but one step at a time. Possibly the Feature Pack installation overwrites the <random>.
If you already did install the Feature Pack and it doesn't work, then you can install boost libraries from here:

As you can see from this library list, Random is included in boost, and it says: Standard ... TR1.

The uniform_int_distribution class header file is defined here:

You wrote that you read that you had to install SP1. Possibly that was just to get the <random> feature, but appears not to include the uniform_int_distribution class.
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Visual C++.NET

From novice to tech pro — start learning today.