#include <iostream>
#include <conio>
#include <stdlib>
int main()
{
int a,b,c,d;
cout<<"Enter the starting number"<<endl;
cin>>a;
srand(a);
b=rand()%RAND_MAX;
c=rand()%200;
d=rand()%10+200;
cout<<"The number between 0 and "<<RAND_MAX<<" is : "<<b<<endl;
cout<<"The number between 0 and 199 is : "<<c<<endl;
cout<<"The number between 200 and 210 is : "<<d<<endl;
getch();
return 0;
}
1: can anyone help to explain what the above code do? I got it from the book...But not really understand it...
2. #include <stdlib> <-what is this library use for? Is that use for random?
Do yourself a favor and toss that book. I say this because if this is a direct copy of the text then the author has no idea what a namespace is or a stream buffer for that matter.
As for your questions, stdlib is a header file not an actual library (there is a difference). Yes, it contains the functions srand() and rand() for psuedo random number generation here is a break down of what that header contains: http://www.cplusplus.com/reference/clibrary/cstdlib/
value % 30 + 1985
after +, the value is bigger than before +, is that means start=1985, end=1985+30=2015(need to add with value before +)? and somemore, from the website it gives only 2014?
value % 100 + 1
after +, the value is smaller than before +, is that means start=1, end=100(no need add with the value before +)??