Question: Problem Given a target integer n , repeatedly generate a random integer in the range of [ 1 , 2 0 ] ( inclusive !

Problem
Given a target integer n, repeatedly generate a random integer in the range of [1,20](inclusive!) using the built-in function randiuntil the target is found, i.e., the function randireturns the same value as n.The trace of the search must be maintained with an array and returned as an output of your function.
For example, if n=5, the output of your function may be
[19,2,1,13,8,5]
[4,1,17,20,1,12,1,3,12,5]
[5]
[1,2,3,4,5]
And infinitely many other possibilities...
Note that because the output array is generated randomlyuntil a certain condition is satisfied (i.e. randireturns the value equal to n), the output array of your function can and most likely will changefor each call even with the same input argument (randomSearchInRange(n)!= randomSearchInRange(n) is probably a true logical statement).
Also, although you can assume nwill be an integer, you will need to ensure that it falls within the interval [1,20]. If nis not within the interval, your function must return an empty array as its output. For example, randomSearchInRange(-3) should return [].
Task
Write a function randomSearchInRangethat takes a single input argumentsand returns a single output array.Your function must use a while loop.

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!