Which of the following choices is better for generating a random integer 0 or 1?
A. (int)Math.random()
B. (int)Math.random() + 1
C. (int)(Math.random() + 0.5)
D. (int)(Math.random() + 0.2)
Answer:C
Which of the following choices is better for generating a random integer 0 or 1?
A. (int)Math.random() B. (int)Math.random() + 1 C. (int)(Math.random() + 0.5) D. (int)(Math.random() + 0.2)
Explanation: int)(Math.random() + 0.5)