I want to write a program that:
- 80% of the time will say
sendMessage("hi");
- 5% of the time will say
sendMessage("bye");
- and 15% of the time will say
sendMessage("Test");
Does it have to do something with Math.random()
?
like
if (Math.random() * 100 < 80) {
sendMessage("hi");
}
else if (Math.random() * 100 < 5) {
sendMessage("bye");
}
else if
, not a simpleif
, so I doubt that's a real option, but still, good catch.