I have tried all of the other posts on this forum, and none of them seem to work! All I want is a completely random number, one that will be different each time i run the program! is this possible in c++?
I have tried all of the other posts on this forum, and none of them seem to work! All I want is a completely random number, one that will be different each time i run the program! is this possible in c++?
Dude, take five minutes to look in a book and it will tell you, its very simple.
You won't get a completely random number without a geiger counter. The best you can do with straight programming would be pseudorandom numbers, such as those created by the rand function in stdlib.h
-Prelude
My best code is written with the delete key.
You mean I need some Uranium or something??Originally posted by Prelude
You won't get a completely random number without a geiger counter.
Uranium wont work, not enough randomness, try Plutonium instead :P.
Signature is optional, I didnt opt for one.
I tried the one in tha faq! it just gives me the same number, over and over and over...
Taken directly from the FAQ. This should produce another random number each time you run it.Code:#include <stdlib.h> //for rand #include <stdio.h> //for printf #include <time.h> //for time int main(void) { srand(time(NULL)); printf("A random number from 0 to 99: %d", rand() % 100); return 0; }
hth
-nv
She was so Blonde, she spent 20 minutes looking at the orange juice can because it said "Concentrate."
When in doubt, read the FAQ.
Then ask a smart question.
Is there anyway to make it into an integer number, like
int x=...and so on
C++ version.Code:#include <stdlib.h> //for rand #include <iostream.h> //for I/O stuff #include <time.h> //for time int main(void) { srand(time(NULL)); int x = rand() % 100; cout << "x is a random number from 0 to 99" << x << endl; return 0; }