randomize character

hi, is there any way so that a randomize number wont be the same ?
like, this code :
1
2
3
4
5
6
7
8
9
10
#include <iostream>
#include <random>
using namespace std;

int main()
{
    random_device lol;
    cout << lol();
}

will always yield this result when runned

 
3499211612

is there any way to make it so the number is different when runned each time ?
Use something like std::uniform_int_distribution
http://en.cppreference.com/w/cpp/numeric/random/random_device/random_device
Thanks
Annoyingly, random_device is not guaranteed to actually be a random device. In particular, MinGW's libstdc++ is known for not providing one.

Although I'm likely to annoy some cryptographers by suggesting this, if your random numbers don't need to be extremely high quality, you can use std::default_random_engine, whose constructor should be able to take a seed.

1
2
const unsigned seed = std::chrono::system_clock::now().time_since_epoch().count();
std::default_random_engine gen(seed);


-Albatross
Topic archived. No new replies allowed.