Generating Random Numbers in Java

0.0(0)
studied byStudied by 0 people
learnLearn
examPractice Test
spaced repetitionSpaced Repetition
heart puzzleMatch
flashcardsFlashcards
Card Sorting

1/7

encourage image

There's no tags or description

Looks like no tags are added yet.

Study Analytics
Name
Mastery
Learn
Test
Matching
Spaced

No study sessions yet.

8 Terms

1
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());

[0, 1)

2
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() * n);

[0, n)

3
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() + 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 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 casting call!

*/

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

Every integers 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?

*/

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

Every integers from [min, max)