Random Number

okay when i just use:
rand()%130
my random numbers are always the same when i close and open my program unless i restart my computer then they change. I understand this comes from the seed. Can any one tell me how to make the number truly random with getting a number from the internet. Because I read you can use random.org but I cant always be connected to the internet so is there a way to get some random numbers?
You can use time(0) as a seed value

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
#include <iostream>
#include <ctime>
using namespace std;
int main ()
{
  srand(time(NULL)); // call srand() only once!
  // time(0) returns number of seconds since January 1, 1970,
  // so random number generator is initialized with a different value each time you call srand

  cout <<rand()%130<<endl;

// ...

  return 0;
}
Last edited on
Thanks boss that did the trick
Topic archived. No new replies allowed.