C Programming – Random Number Generation

C Programming - Random Number Generation

Question 1
The function srand(unsigned)
A
Sets the seed for rand
B
Doesn’t exist
C
Is an error
D
None of the mentioned
Question 2
Which is the best way to generate numbers between 0 to 99?
A
rand()-100
B
rand()%100
C
rand(100)
D
srand(100)
Question 3
 The correct way to generate numbers between minimum and maximum(inclusive) is _____________________.
A
minimum + (rand() % (maximum – minimum));
B
minimum + (rand() % (maximum – minimum + 1));
C
minimum * (rand() % (maximum – minimum))
D
minimum – (rand() % (maximum+minimum));
Question 4
 rand() and srand() functions are used
A
To find sqrt
B
For and operations
C
For or operations
D
To generate random numbers
Question 5
What is the return type of rand() function?
A
short
B
int
C
long
D
double
Question 6
 Which of the following can be used for random number generation?
A
random()
B
rnd()
C
rndm()
D
None of the mentioned
Question 7
Which of the following snippet will effectively generate random numbers?
A
rand();
B
rand(10);
C
rand(time(NULL));
D
All of the mentioned
Question 8
Which among the following is correct function call for rand and random?
A
rand() and random();
B
rand() and random(1);
C
rand(1) and random(1);
D
rand(1) and random();
Question 9
 For the function call time(), what type of parameter is accepted?
A
int
B
int *
C
time_t
D
time_t *
Question 10
What is the output of this C code?
    #include 
    #include 
    int main()
    {
    printf("%d\n", rand() % 1000);
    return 0;
    }
A
Compile time error
B
An integer between 0-1000
C
An integer between 0-999 including 0 and 999.
D
An integer between 0-1000 including 1000
Question 11
What is the output of this C code?
    #include 
    #include 
    int main()
    {
    srand(9000);
    printf("%d\n", rand());
    return 0;
    }
A
Compile time error
B
An integer in the range 0 to RAND_MAX.
C
A double in the range 0 to 1
D
A float in the range 0 to 1.
Question 12
What is the output of this C code?
    #include 
    int main()
    {
    printf("%d\n", srand(9000));
    return 0;
    }
A
Compile time error
B
An integer in the range 0 to 9000
C
A float in the range 0 to 1
D
A double in the range 0 to 9000
Question 13
What is the output of this C code?
    #include 
    int main()
    {
    srand(time(NULL));
    printf("%d\n", rand());
    return 0;
    }
A
Compile time error
B
An integer in the range 0 to RAND_MAX.
C
A double in the range 0 to 1
D
A float in the range 0 to 1.
Question 14
 In the below program everytime program is run different numbers are generated.
A
true
B
false
C
Depends on the platform
D
Depends on the compiler
Question 15
In the below program everytime program is run different numbers are generated.
    #include 
    int main()
    {
    srand(time(NULL));
    printf("%d\n", rand());
    return 0;
    }
A
true
B
false
C
Depends on the platform
D
Depends on the compiler
Question 16
Which of these is a correct way to generate numbers between 0 to 1(inclusive) randomly?
A
rand() / RAND_MAX
B
rand() % 2
C
rand(0, 1)
D
None of the mentioned


Check Your Answers:

  1. A
  2. B
  3. B
  4. D
  5. B
  6. A
  7. A
  8. A
  9. D
10. C
11. B
12. A
13. B
14. B
15. A
16. A


SHARE

Unknown

  • Image
  • Image
  • Image
  • Image
  • Image
    Blogger Comment
    Facebook Comment

0 comments:

Post a Comment