Skip to main content
Became Hot Network Question
Tweeted twitter.com/StackCodeReview/status/1342394676414980096

I'm a newbienew to programming and. I have a question regarding the usage of c++11 random header to generate random numbers caught my eye. I have been tryingtried to learn it for some time, but I was unsuccessful. Recently, II've tried this waythe following approach and it worked. Any adivceadvice on how to improve it or. Is there a bettergood source to learn it frommore about this?

Here's the code:

#include <iostream>
#include <random>
#include <ctime>
int main()
{
   std::default_random_engine random_engine(time(0));
   for (int i = 1; i <= 100; i++)
   {
    std::uniform_int_distribution<int> num(1, 100);
    std::cout << i << "==> " << num(random_engine) << std::endl;
   }
    return 0;
}

I'm a newbie to programming and the usage of c++11 random header to generate random numbers caught my eye. I have been trying to learn it for some time, but I was unsuccessful. Recently, I tried this way and it worked. Any adivce on how to improve it or a better source to learn it from?

#include <iostream>
#include <random>
#include <ctime>
int main()
{
   std::default_random_engine random_engine(time(0));
   for (int i = 1; i <= 100; i++)
   {
    std::uniform_int_distribution<int> num(1, 100);
    std::cout << i << "==> " << num(random_engine) << std::endl;
   }
    return 0;
}

I'm new to programming. I have a question regarding the usage of c++11 random header to generate random numbers. I tried to learn it, but was unsuccessful. Recently, I've tried the following approach and it worked. Any advice on how to improve it. Is there a good source to learn more about this?

Here's the code:

#include <iostream>
#include <random>
#include <ctime>
int main()
{
   std::default_random_engine random_engine(time(0));
   for (int i = 1; i <= 100; i++)
   {
    std::uniform_int_distribution<int> num(1, 100);
    std::cout << i << "==> " << num(random_engine) << std::endl;
   }
    return 0;
}
Source Link
Axel Bozic
  • 161
  • 2
  • 3

Using c++11 random header to generate random numbers

I'm a newbie to programming and the usage of c++11 random header to generate random numbers caught my eye. I have been trying to learn it for some time, but I was unsuccessful. Recently, I tried this way and it worked. Any adivce on how to improve it or a better source to learn it from?

#include <iostream>
#include <random>
#include <ctime>
int main()
{
   std::default_random_engine random_engine(time(0));
   for (int i = 1; i <= 100; i++)
   {
    std::uniform_int_distribution<int> num(1, 100);
    std::cout << i << "==> " << num(random_engine) << std::endl;
   }
    return 0;
}