can any one please tell me am i done my question right?
my question is to store store 1035 to 1265 random in a character array and display the array.
and im not sure whats this srand is doing?

int main(){
char b[30];
for(int i=0;i<30;i++)   {
for(int i=0;i<10;i++)   {
return 0;}

Edited by AmerJamil: n/a

6 Years
Discussion Span
Last Post by Ancient Dragon

srand() is ued to seed the random number generator. If you call srand() with the same number every time your program is run rand() will generate the same sequence of random numbers, which is the default if the program never calls srand(). To get rand() to generate a different set of random numbers each time the program is run you need to call srand() with a different seed number. The easiest way to do that is to call time() function from time.h, like this: srand( time(0) ); you might have to typecast the return value of time() to unsigned int if your compiler complains about it.

What srand() does not do: that function does NOT set the lower value of the numbers returned by rand(), as you are implying in your program. See the examples here to find out the correct way to do that.

Edited by Ancient Dragon: n/a


my question is to store 1035 to 1265 random in a character array and display the array.


Yes, I know what you question was -- but you asked if it was done. How am I supposed to know if you are finished with it or not?


I already told you your code is wrong and how to fix it. You have not posted your corrected code. And you can easily check it yourself by compiling and running it. When you run that program it will tell you whether it is right or wrong.

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.