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.

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.

Recommended Answers

All 3 Replies

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++

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, learning, and sharing knowledge.