Question: I need this in a method in java. Preferably eclipse! An efficient algorithm to randomly generate these unique 20 tickets among the 100 tickets is

I need this in a method in java. Preferably eclipse! An efficient algorithm to randomly generate these unique 20 tickets among the 100 tickets is as follows: 1. Create an array of 101 elements 2. Randomly generate a number between 1 and 100, representing a ticket number 3. Insert that number in it's array position if the current value in that position is zero, otherwise ignore it because the number has already been generated 4. keep track of how many numbers have been generated so far 5. Repeat steps 2 to 4 until 20 distinct ticket numbers have been generated 6. Finally, go through the array and prints all the non zero elements as the ticket numbers

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Programming Questions!