Numbers


  1. What is the range of numbers returned by Math.random() method?











  1. View Hint View Answer Discuss in Forum

    NA

    Correct Option: B

    Math.random() returns only double value greater than or equal to 0.0 and less than 1.0.


  1. How many bits are used for generating random numbers?











  1. View Hint View Answer Discuss in Forum

    NA

    Correct Option: D

    Random number can accept 64 bits but it only uses 48 bits for generating random numbers.



  1. What would be the output of following code snippet?
    int ran = random.nextInt(10) + 1;











  1. View Hint View Answer Discuss in Forum

    NA

    Correct Option: C

    random.nextInt(10) + 1; returns random numbers between 1 to 10 including 1 and 10.


  1. What would be the output of following code snippet?
    int ran = random.nextInt(10) + 2;











  1. View Hint View Answer Discuss in Forum

    NA

    Correct Option: B

    random.nextInd(10) + 2; returns random numbers between 2 to 11 including 2 and 11. it follows “nextInt(max – min +1) + min” formula.



  1. Math.random() guarantees uniqueness?











  1. View Hint View Answer Discuss in Forum

    NA

    Correct Option: A

    Math.random() doesn’t guarantee uniqueness. To guarantee uniqueness we must store the generated value in the database and compare against already generated values.