Generating Random Numbers in Java

0.0(0)
Studied by 0 people
call kaiCall Kai
learnLearn
examPractice Test
spaced repetitionSpaced Repetition
heart puzzleMatch
flashcardsFlashcards
GameKnowt Play
Card Sorting

1/9

encourage image

There's no tags or description

Looks like no tags are added yet.

Last updated 11:32 PM on 9/13/25
Name
Mastery
Learn
Test
Matching
Spaced
Call with Kai

No analytics yet

Send a link to your students to track their progress

10 Terms

1
New cards

//What is the range that this call will generate?

System.out.println(Math.random());

[0, 1)

2
New cards

/**Suppose n is a correctly instantiated int variable

* What is the range that this call will generate?

*/System.out.println(Math.random() * n);

[0, n)

3
New cards

/**Suppose n is a correctly instantiated int variable

* What is the range that this call will generate?

*/

System.out.println(Math.random() + n);

[0 + n, 1 + n)

4
New cards

/**Suppose max and min are correctly instantiated int variables

* What is the range that this call will generate?

*/

System.out.println((Math.random()*(max - min)) + min);

[min, max)

5
New cards

/**What is the range that this call will generate?

* Pay attention to the casting call!

*/

System.out.println((int)(Math.random());

0

6
New cards

**Suppose n is a correctly instantiated int variable

* What is the range that this call will generate?

* Careful with the casting call!

*/

System.out.println((int)(Math.random() * n);

All integers from [0,n)

7
New cards

/**Suppose n is a correctly instantiated int variable

* What is the range that this call will generate?

* Careful with the casting call!

*/

System.out.println((int)(Math.random()) + n);

Every integer from [0 + n, 1 + n)

8
New cards

/**Suppose max and min are correctly instantiated int variables—

* What is the range that this call will generate?

* Careful with the casting call!

*/

System.out.println((int)(Math.random()*(max - min)) + min);

Every integer from [min, max)

9
New cards

What statement would you use to generate a random number from a minimum value, to a maximum value—exclusive?

(Math.random()*(max - min)) + min

10
New cards

What statement would you use to generate a random number from a minimum value, to a maximum value—inclusive?

(Math.random()*((max + 1) - min)) + min

Explore top flashcards

flashcards
Skeletal System
30
Updated 832d ago
0.0(0)
flashcards
WHAP Period 2 Vocabulary Terms
43
Updated 936d ago
0.0(0)
flashcards
Celebraciones
68
Updated 1133d ago
0.0(0)
flashcards
Am Hist Unit 3 Vocab
25
Updated 1110d ago
0.0(0)
flashcards
Pd. 7 OOL
30
Updated 462d ago
0.0(0)
flashcards
Political Spectrum Quiz
31
Updated 1044d ago
0.0(0)
flashcards
Skeletal System
30
Updated 832d ago
0.0(0)
flashcards
WHAP Period 2 Vocabulary Terms
43
Updated 936d ago
0.0(0)
flashcards
Celebraciones
68
Updated 1133d ago
0.0(0)
flashcards
Am Hist Unit 3 Vocab
25
Updated 1110d ago
0.0(0)
flashcards
Pd. 7 OOL
30
Updated 462d ago
0.0(0)
flashcards
Political Spectrum Quiz
31
Updated 1044d ago
0.0(0)