Home » Ask & Discuss » Board Exams - CBSE, ICSE, State Boards » Computer Science « Back to Discussion



Computer Science

Blazing goIITian

Joined: 21 Oct 2008
Post: 473
23 Mar 2009 20:46:06 IST
0 People liked this
2
417 View Post
URGENT!!-Ans req within 2day nite please...
None

URGENT!!-Ans req within 2day nite please...

pls tell me how randomize() works
Ex..
#include<stdlib.h>
#include<iostream.h>
void main()
{
randomize();
int m[]={99,92,94,96,93,95}, M;
M=m[1+random(2)];
cout<<M;
}

1. 99
2. 94
3. 96
4. NONE

Pls tell whether my reason is correct!
Random(2)- will return either return 0,1,2(doubt1-is 2 included)

So possible values inside[] are 1,2,3
so the possibilities are 99,92,94..
Which is correct??


Share this article on:

Comments (2)

Chuck Norris's Avatar

Scorching goIITian

Joined: 25 Nov 2008
Posts: 210
23 Mar 2009 20:50:15 IST
1 people liked this

random(2) generates 2 numbers starting from 0...therefore 0 and 1 is generated.now 1 is added to it so it becomes 1 or 2..in the array the location corresponds to the elements 92 and 94 ...therefore option 2 is right


Blazing goIITian

Joined: 7 May 2007
Posts: 1724
23 Mar 2009 20:58:13 IST
1 people liked this

random(n) generates  n  nos. starting from 0.

random(2) generates  0,1 .

now 1 is added to them.

so result obtained will be 1,2.

here location should be 92 or 94.

i think option b i.e 94 should be correct answer.




Quick Reply


Reply

Some HTML allowed.
Keep your comments above the belt or risk having them deleted.
Signup for a avatar to have your pictures show up by your comment
If Members see a thread that violates the Posting Rules, bring it to the attention of the Moderator Team
Free Sign Up!

Preparing for IIT-JEE ?

Arihant Revision Package for IIT JEE - Books, Practice Tests + Rank Predictor


@ INR 1,995/-

For Quick Info

Name

Mobile No.

Find Posts by Topics

Physics.

Topics

Mathematics.

Chemistry.

Biology

Parents

Board

Fun Zone

Sponsored Ads