1/9
Looks like no tags are added yet.
Name | Mastery | Learn | Test | Matching | Spaced |
---|
No study sessions yet.
//What is the range that this call will generate?
System.out.println(Math.random());
[0, 1)
/**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)
/**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)
/**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)
/**What is the range that this call will generate?
* Pay attention to the casting call!
*/
System.out.println((int)(Math.random());
0
**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)
/**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)
/**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)
What statement would you use to generate a random number from a minimum value, to a maximum value—exclusive?
(Math.random()*(max - min)) + min
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