Question

In: Computer Science

The Random class implements a random number generator, which produces sequences of numbers that appear to...

The Random class implements a random number generator, which produces sequences of numbers that appear to be random. To generate random integers, you construct an object of the Random class, and then apply the nextInt method. For example, the call generator.nextInt(6) gives you a random number between 0 and 5. Write a program DieSimulator that uses the Random class to simulate the cast of a die, printing a random number between 1 and 6 every time that the program is ru

Solutions

Expert Solution

Hi,

Following is the code for generating random number between 1 to 6

uncomment the for loop if you want to generate more random numbers in one run.

Code

import java.util.Random;

public class DieSimulator
{
public static void main(String[] args)
{
//random class
Random rand = new Random();
//numbers between 1 to 6
int minRange = 1, maxRange= 6;
//random value
int value = rand.nextInt(maxRange - minRange) + minRange;
System.out.println("Random Number :" +value);
//genereating 10 random numbers in a for loop
/* for(int i=0;i<10;i++){
int value = rand.nextInt(maxRange - minRange) + minRange;
System.out.println("Random Number :"+value);
}*/
}
}

output


Related Solutions

Suppose you have access to a random number generator Rng() that generates uniform random numbers in...
Suppose you have access to a random number generator Rng() that generates uniform random numbers in {0, 1, . . . , n − 1}. Design a function uses Rng() generate a uniform random number in {0, 1, . . . , m − 1}, where m ≤ n
Questions 36-39: Six numbers are selected at random from a random number generator and entered into...
Questions 36-39: Six numbers are selected at random from a random number generator and entered into each of four rows. The summary statistics are presented in the chart below. Mean SD   Row 1 5.8  0.78 Row 2 3.6  0.23 Row 3 5.5  0.32 Row 4 4.0  0.59 Assume the populations are normal with equal variances. It is of interest to test the following: Ho: μ1 = μ2 = μ3 = μ4 36. What are the degrees of freedom for the...
Use a random number generator to produce 1000 uniformly distributed numbers with a mean of 10, a
Use a random number generator to produce 1000 uniformly distributed numbers with a mean of 10, a minimum of 2, and a maximum of 18. Obtain the mean and the histogram of these numbers, and discuss whether they appear uniformly distributed with the desired mean.
Use a random number generator to produce 1000 normally distributed numbers with a mean of 20
Use a random number generator to produce 1000 normally distributed numbers with a mean of 20 and a variance of 4. Obtain the mean, variance, and histogram of these numbers, and discuss whether they appear normally distributed with the desired mean and variance.
Below are 50 random numbers taken from a random number generator. 0.534 0.401 0.401 0.445 0.445...
Below are 50 random numbers taken from a random number generator. 0.534 0.401 0.401 0.445 0.445 0.125 0.094 0.094 0.104 0.104 0.345 0.259 0.259 0.288 0.288 0.785 0.589 0.589 0.654 0.654 0.975 0.731 0.731 0.813 0.813 0.834 0.626 0.626 0.695 0.695 0.683 0.512 0.512 0.569 0.569 0.322 0.242 0.242 0.268 0.268 0.526 0.395 0.395 0.438 0.438 0.234 0.176 0.177 0.198 0.196 a) Using 5 class intervals, determine the computed chi-square value. Answer in 1 decimal place.    b) What is...
1. A random number generator claims to randomly choose real numbers between 0 and 3000. (a)...
1. A random number generator claims to randomly choose real numbers between 0 and 3000. (a) If this is true, what kind of distribution would the randomly chosen numbers have? (b) What would be the mean of this distribution? (c) What would be the standard deviation of this distribution? (d) Say we take a sample of 65 generated numbers and obtain a sample mean of 1552. What do we know about the sampling distribution of the sample mean and how...
A random number generator produces a sequence of 18 digits (0, 1, ..., 9). What is...
A random number generator produces a sequence of 18 digits (0, 1, ..., 9). What is the probability that the sequence contains at least one 3? (Hint: Consider the probability that it contains no 3's. Round your answer to four decimal places.)
A random number generator picks a number from 7 to 68 in a uniform manner. Round...
A random number generator picks a number from 7 to 68 in a uniform manner. Round answers to 4 decimal places when possible. The mean of this distribution is The standard deviation is The probability that the number will be exactly 42 is P(x = 42) = The probability that the number will be between 16 and 28 is P(16 < x < 28) = The probability that the number will be larger than 48 is P(x > 48) =...
1.) Using excel. A random number generator picks a number from one to nine in a...
1.) Using excel. A random number generator picks a number from one to nine in a uniform manner. X ~ _________ Graph the probability distribution. f(x) = _________ μ = _________ σ = _________ P(3.5 < x < 7.25) = _________ P(x > 5.67) P(x > 5|x > 3) = _________ Find the 90th percentile. 2) using excel A subway train on the Red Line arrives every eight minutes during rush hour. We are interested in the length of time...
A random number generator picks a number from 18 to 64 in a uniform manner. Round...
A random number generator picks a number from 18 to 64 in a uniform manner. Round answers to 4 decimal places when possible. The mean of the distribution is: The standard deviation is: The probability that the number will be exactly 20 is P(x = 20) = The probability that the number will be between 24 and 26 is P(24 < x < 26) = The probability that the number will be larger than 32 is P(x > 32) =...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT