Ask Question

How do I write: "get a random number between - 10 and 11 but it cannot be 0"? (java)

+4
Answers (1)
  1. 7 November, 06:31
    0
    generate a random number in a known range and map the result to the range you want

    Explanation:

    Use any of the usual methods to get a random number in the range 0-20, then subtract 9. Use an IF statement to test if the result is 0. If it is, replace the value with - 10.
Know the Answer?
Not Sure About the Answer?
Find an answer to your question 👍 “How do I write: "get a random number between - 10 and 11 but it cannot be 0"? (java) ...” in 📗 Computers & Technology if the answers seem to be not correct or there’s no answer. Try a smart search to find answers to similar questions.
Search for Other Answers