Randomize

Is this code logically correct
radomize();
time();
int s=rand()%10

info:this cod runs in turbo c++
borland
If you are trying to put a random number into variable s, you should first seed the generator with a call to srand(unsigned int), then assign that value to s. By using time(), i assume you want to use time() in your generator?

The resulting code snippet should look like this:
1
2
srand(time(NULL));
int s=rand()*10;


This creates a random number, s, that is between 0 and 9.

I'm not sure what randomize() does; I've never used it before. The above method, though, works on most good compilers.

Thanks,
hnefatl

P.S. It makes posts a lot easier to read if you use the code formatting option when writing code in a post. Just write code in square brackets before the code, and /code in square brackets afterward. That's just me being perfectionist though!
Topic archived. No new replies allowed.