Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Suppose you have a list of customers, labeled from 1 to n, and you want to choos

ID: 3620982 • Letter: S

Question

Suppose you have a list of customers, labeled from 1 to n, and you want to choose a random subset of them of size m(where m<n). Write a sub to do this. It should first ask the user for n and m, using two input boxes. It should them fill an array of size m called CHOSEN, where CHOSEN(1) is the index of the first person chosen, CHOSEN(2) is the index of the second person chosen, and so on. No person can be chosen more than once, so no two elements of the chosen array should have the same value. Finally, the sub should list the values of the chosen array in column A of a worksheet. Note that you can use Excel's RandBetween function to generate a random integer from 1 to n.

Explanation / Answer

In VBA, 

Sub GetInput()
  MyInput1 = InputBox("Enter upper value n")
  MyInput2 = InputBox("Enter lower value m")
  CHOSEN = Int((MyInput1 - MyInput2 + 1) * Rnd + MyInput2)
  MsgBox ("The random number is ") & (CHOSEN)
  End Sub

In Excel,must write formula using RandBetween function

 1. Enter a list of names in column A

2. Now enter the below formula in the cell then it will return the random name.

=INDEX ($A: $A, RANDBETWEEN (1, COUNTA ($A: $A)), 1)

This will pick a name at random from your list in column A

 

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote