AP® Computer Science A glossary

Math.random

Also called: random()

Course: AP® Computer Science A Shows up in: Unit 1: Using Objects and Methods

A Math class method that returns a double greater than or equal to 0.0 and less than 1.0.

Appears in the course and exam description (CED): 1.11.A.21.11.A.3

To get an int from min to max inclusive, use (int) (Math.random() * (max - min + 1)) + min. Keep the parentheses: (int) Math.random() * 6 is always 0.

Learn it properly, with a checkpoint 1.11 Math Class

Related terms

Was this page helpful?

No names are ever shown, and every public comment is checked by us first. Please do not include personal details. To get a reply, email [email protected].

↑ Top

Enlarged view of the selected figure