question archive Problem Given a target integer n, repeatedly generate a random integer in the range of [1, 20] (inclusive!) using the built-in function randi until the target is found, i

Subject:Computer SciencePrice: Bought3

Problem

Given a target integer n, repeatedly generate a random integer in the range of [1, 20] (inclusive!) using the built-in function randi until the target is found, i.e., the function randi returns 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]

• [51

" [1, 2, 3, 4, 5]

= And infinitely many other possibilities...

Note that because the output array is generated randomly until a certain condition is satisfied (i.e. randi returns the value equal to n), the output array of your function can and most likely will change for each call even with the same input argument (randomSearchInRange(n) != randomSearchInRange(n) is probably a true logical statement).

Also, although you can assume n will be an integer, you will need to ensure that it falls within the interval [1, 20]. If n is not within the interval, your function must return an empty array as its output. For example, randomSearchinRange(-3) should return O.

Task

Write a function randomSearchInRange that takes a single input arguments and returns a single output array. Your function must use a while loop.