How does random and randomize functions work?
Please help me!
What are the different outputs that can be predicted from this program? And How? Explain.

#include<iostream.h>
#include<stdlib.h>
void main()
{   randomize()
    int Game[] = {10,16},P;  //what does this mean?
    int Turn = random(2) + 5;
    for(int T = 0; T<2; T++)
    {    P = random(2);
         cout<<Game[P] + Turn <<"#";
    }
}

I got the output of this program, but how the output was generated, I have no Idea. Please help. ASAP.

What C++ compiler are you using?
It would help to show your programs output also.

I am using Turbo C++. But I have to guess the outputs theoretically without using the compiler. That's why I am asking how does this program work? there must be some basic pattern or something?

It's over due to get a modern C++ compiler that uses standard C++

Hints:
srand( time(0) ) ; // seed rand

int x = rand()%2; // x is now 0 or 1

int ary[] = {10, 100};
int y = ary[x]; // y is now 10 or 100
...

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.