

this will generate a random number between 1 to 6 using the formula. Using it you can do the following: Random rnd new Random() int randomNumberFromArray arrayrnd. Java has a Random class in the java.util package. Then simply get your int from your array: myArraymyRandomNumber Answer 9.

for doing this we will initialize the lower limit of the rand to 1 and The upper limit of the rand function to 6. You will want to generate a random number from 0 to your integers length - 1. On average, one can expect to lose about 90 cents on a lottery ticket. The random numbers are: 1 5 4 4 4 2 3 2 4 3 Explanation: This program declares a variable num that generates a random number between 1 to 6. Of these possible outcomes, only one would match all six numbers on the player’s ticket, so the probability of winning the grand prize is: Since there is no stipulation that the numbers be in any particular order, the number of possible outcomes of the lottery drawing is 48 C 6 = 12,271,512. In order to compute the probability, we need to count the total number of ways six numbers can be drawn, and the number of ways the six numbers on the player’s ticket could match the six numbers drawn from the machine. Compute the probability that you win the million-dollar prize if you purchase a single lottery ticket. In this post, I will discuss different ways to generate random numbers based on different types of requirements. In this lottery, the order the numbers are drawn in doesn’t matter. If the six numbers drawn match the numbers that a player had chosen, the player wins $1,000,000. In a certain state’s lottery, 48 balls numbered 1 through 48 are placed in a machine and six of them are drawn at random.
