DSA Challenge: Generate Uniform Random Numbers Using a Binary Generator
A developer has shared a data structures and algorithms problem sourced from the book 'Elements of Programming Interviews in Java' by Lee, Aziz, and Prakash. The challenge, listed as problem 4.10, asks how to generate a uniformly random integer between two values, a and b inclusive, using only a binary random generator that returns 0 or 1 with equal probability. A hint accompanying the problem draws an analogy to simulating a three-sided coin using a two-sided coin. The post also nudges solvers to consider what the expression b minus a represents and how it can help minimize calls to the generator. This is the author's first post on the platform, with plans to share more interesting DSA and interview-style problems in the future.
This is an AI-generated summary. ShortSingh links to the original source for the complete article.

Discussion (0)
Log in to join the discussion and vote.
Log in