0

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.

2
Contributors
3
Replies
20
Views
2 Years
Discussion Span
Last Post by David W
0

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

Edited by David W

0

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?

0

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

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.