### Help using random numbers

i had the following problem in my book:

 ``12345678910111213141516`` ``````#include #include #include void main() { clrscr(); randomize(); int Game[]={10,16},P; int Turn=random(2)+5; for(int T=0;T<20;T++) { P=random(2); cout<

The output comes like 16#22#16#16#16#22#....20 times... Why the output of this always comes either 16# or 22#?? why not 15# or 21#?? i would like to the mechanism of this program. Thanks. turn=random(2)+5; if random(2) gives 0 then turn becomes turn=0+5=5 which implies that i should get 10+5=15 and 16+5=21 along with 16 and 22 but i m not getting them.

We got the above question in our computer science theory exam and we were to chose the correct answer(i.e it generates 16 and 22) but how will i am going to know that it will generate only 16 and 22. As i explained above 15 and 21 are also possible..
Last edited on
Seeding was required
`#include <ctime> `
and use `srand(time(0)); `
to Seed RANDom numbers!
i had the following problem in my book:

 ``1234`` ``````#include #include #include void main()``````

Get rid of that crappy book.

Topic archived. No new replies allowed.