void main()
{
randomize();
char city[][10]={"DEL","CHN","KOL","BOM","BNG"};
int i,fly;
for(i=0;i<3;i++)
{
fly=random(2)+1;
cout<<city[fly]<<":";
}
}
What is the output of the following code snippet?
void main()
{
randomize();
char city[][10]={"DEL","CHN","KOL","BOM","BNG"};
int i,fly;
for(i=0;i<3;i++)
{
fly=random(2)+1;
cout<<city[fly]<<":";
}
}
What is the output of the following code snippet?
If you want the same output every time you run a program using random number generators, you want to seed the generator with the same value every time. For example:
#include <cstdlib>
#include <iostream>
using namespace std:
int main() {
srand( 42 ); // generator always seeded with same value
for ( int i = 0; i < 10; i++ ) {
cout << rand() << endl;
}
}
always produces the same sequence.