What method is used in Java to generate a random number between 0.0 (inclusive) and 1.0 (exclusive)?

Java Random Number Generation Quiz

Quiz
•
Computers
•
12th Grade
•
Hard
Patrick Bryar
FREE Resource
10 questions
Show all answers
1.
MULTIPLE CHOICE QUESTION
30 sec • 1 pt
Math.randomInt()
Random.nextInt()
Random.generate()
Math.random()
2.
MULTIPLE CHOICE QUESTION
30 sec • 1 pt
Which of the following formulas can be used to generate a random integer between 0 and 100 in Java?
int randomNum = (int)(Math.random() * 101);
int randomNum = (int)(Math.random() * 100);
int randomNum = Math.random() * 100;
int randomNum = Random.nextInt(100);
3.
MULTIPLE CHOICE QUESTION
30 sec • 1 pt
What is the return type of the Math.random() method in Java?
int
double
float
long
4.
MULTIPLE CHOICE QUESTION
30 sec • 1 pt
What is the range of values returned by Math.random() in Java?
0.0 (inclusive) to 1.0 (exclusive)
0.0 (exclusive) to 1.0 (exclusive)
0.0 (inclusive) to 1.0 (inclusive)
0.0 (exclusive) to 1.0 (inclusive)
5.
MULTIPLE CHOICE QUESTION
30 sec • 1 pt
To generate a random integer between 1 and 10, which of the following expressions is correct?
int randomNum = (int)(Math.random() * 10) + 1;
int randomNum = Math.random() * 10 + 1;
int randomNum = (int)(Math.random() * 11);
int randomNum = Random.nextInt(10) + 1;
6.
MULTIPLE CHOICE QUESTION
30 sec • 1 pt
What is the purpose of casting in the expression (int)(Math.random() * 101)?
To generate a floating-point number
To ensure the result is always positive
To increase the range of random numbers
To convert the double result to an integer
7.
MULTIPLE CHOICE QUESTION
30 sec • 1 pt
Which of the following is a correct way to generate a random number between 0 and 50?
int randomNum = (int)(Math.random() * 50);
int randomNum = Math.random() * 50;
int randomNum = (int)(Math.random() * 51);
int randomNum = Random.nextInt(50);
Create a free account and access millions of resources
Similar Resources on Wayground
10 questions
Control Structures

Quiz
•
12th Grade
10 questions
AP CSA Unit 1 & 2 Review

Quiz
•
9th - 12th Grade
15 questions
JavaScript and Graphics

Quiz
•
9th - 12th Grade
15 questions
Python Programming

Quiz
•
5th Grade - University
8 questions
J277 - 2.2 - Random Number Generation

Quiz
•
10th Grade - University
15 questions
Array

Quiz
•
10th - 12th Grade
15 questions
Area With Arrays

Quiz
•
10th - 12th Grade
10 questions
C++ Programming Quiz

Quiz
•
12th Grade
Popular Resources on Wayground
25 questions
Equations of Circles

Quiz
•
10th - 11th Grade
30 questions
Week 5 Memory Builder 1 (Multiplication and Division Facts)

Quiz
•
9th Grade
33 questions
Unit 3 Summative - Summer School: Immune System

Quiz
•
10th Grade
10 questions
Writing and Identifying Ratios Practice

Quiz
•
5th - 6th Grade
36 questions
Prime and Composite Numbers

Quiz
•
5th Grade
14 questions
Exterior and Interior angles of Polygons

Quiz
•
8th Grade
37 questions
Camp Re-cap Week 1 (no regression)

Quiz
•
9th - 12th Grade
46 questions
Biology Semester 1 Review

Quiz
•
10th Grade