A programmer is creating a simulation of a city where natural disasters can
randomly occur.
This incomplete code segment simulates a Godzilla disaster:
IF ()
{
cityHealth - cityHealth - 30
disasterMode - "godzilla"
}
The code should only give Godzilla a 2% chance of storming the city.
Which of these can replace so that the code
works as intended?
Choose 1 answer:
A
RANDOM (1, 100) <= 2
B
RANDOM (1, 100) >= 98
RANDOM (1, 100) <= 98
C
RANDOM (1, 100) >= 2
D
Let's evaluate the given options:
1.
Option A: `RANDOM(1, 100) <= 2`
- This condition will be true if the random number generated is 1 or 2.
- Probability: or 2%.
2.
Option B: `RANDOM(1, 100) >= 98`
- This condition will be true if the random number generated is 98, 99, or 100.
- Probability: or 3%.
3.
Option C: `RANDOM(1, 100) <= 98`
- This condition will be true if the random number generated is between 1 and 98.
- Probability: or 98%.
4.
Option D: `RANDOM(1, 100) >= 2`
- This condition will be true if the random number generated is between 2 and 100.
- Probability: or 99%.
The correct answer is
Option A: `RANDOM(1, 100) <= 2`.
Here is the code snippet with the correct condition:
Not the question you are looking for? Ask here!
Enter question by text
Enter question by image
Unlock Smarter Learning with AskSia Super!
Join Super, our all-in-one AI solution that can greatly improve your learning efficiency.