Machine Learning Coding Problems

<p>Consider only the range [1, K*(b-a+1)] from the values of Q. Among this range, if we divide it into b-a+1 equal parts each of size K, then for any integer in the 1st part i.e. [1, K] we return 1, for 2nd part [K+1, 2K] return 2 and so on.</p> <p>Thus int((Q-1)/K)+1 will return random integer in the range [1, b-a+1]. To return in the range [a, b], add a-1 to the output i.e.&nbsp;<strong>a+int((Q-1)/K).</strong></p> <p><iframe frameborder="0" height="413" scrolling="no" src="https://mecha-mind.medium.com/media/240869a90dc77e4136ec4eae7b988fa3" title="generate_random.py" width="680"></iframe></p> <p>Expected number of times while loop executes is 7^P/K*(b-a+1).</p> <p><a href="https://mecha-mind.medium.com/ds-algo-problems-ml-coding-878b852ea421"><strong>Visit Now</strong></a></p>