This question has been answered by 666 people and has an average rating of 3.49 (based on 390 ratings)
Which of the following expressions will simulate a dice roll (in other words, the value stored in the variable dice will be either 1, 2, 3, 4, 5 or 6)? You can assume that the seed for the random number generator has already been set to the current time.
Option | Alternative | First answers |
Confirmed answers |
---|---|---|---|
A |
dice = (rand() % 5) + 1; |
158 (23.72%) |
1 (0.83%) |
B |
dice = (rand() % 6) + 1; |
410 (61.56%) |
120 (99.17%) |
C |
dice = (rand() % (6 - 1 + 1)); |
66 (9.91%) |
0 (0.00%) |
D |
dice = (rand() % 1) + 6; |
20 (3.00%) |
0 (0.00%) |
E |
dice = (rand() % 10) - 4; |
12 (1.80%) |
0 (0.00%) |
The following explanation has been provided relating to this question:
If you edit the question, this current version will be archived and a new version of the question will be created (this new version will still appear as being authored by the original author, however all ratings, comments and responses will be reset).
If you feel this question is inappropriate for this course, you can delete it from the system by pressing the button below. All associated ratings and feedback comments will also be deleted if you choose to remove this question.