Generating Random Integers in a Range
Which of the following Java statements correctly generates a random integer in the range from -23 to 8, inclusive?
A
int rand = (int)(Math.random() * 32 + 8);
B
int rand = (int)(Math.random() * 32 - 23);
C
int rand = (int)(Math.random() * 31 - 8);
D
int rand = (int)(Math.random() * 15 + 23);
Question Leaderboard
| Rank | |||||
|---|---|---|---|---|---|
| #1 | 6test6ing6 | 1 | 1 | 0m 00s | 100 |
| #2 | jeonsaw1723 | 1 | 1 | 0m 33s | 67 |
| #3 | patrickmeijer009 | 1 | 2 | 0m 46s | 44 |
| #4 | keithy.mcbeefy | 1 | 1 | 0m 58s | 42 |
| #5 | angelajxi11 | 0 | 1 | 0m 00s | -10 |
| #6 | akerayseduru777 | 0 | 1 | 0m 00s | -10 |
| #7 | parth.taur227 | 1 | 1 | 2m 37s | -57 |
| #8 | lsj08030922 | 1 | 1 | 2m 44s | -64 |
| #9 | bommasam000 | 0 | 3 | 0m 41s | -71 |
Items per page:
10
1 – 9 of 9
