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 inclusive using the builtin function randiuntil the target is found, ie the function randireturns the same value as nThe trace of the search must be maintained with an array and returned as an output of your function.
For example, if n the output of your function may be
And infinitely many other possibilities...
Note that because the output array is generated randomlyuntil a certain condition is satisfied ie 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 randomSearchInRangen randomSearchInRangen 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 If nis not within the interval, your function must return an empty array as its output. For example, randomSearchInRange 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
Question Has Been Solved by an Expert!
Get step-by-step solutions from verified subject matter experts
Step: 2 Unlock
Step: 3 Unlock
