<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DEV Community: Connor</title>
    <description>The latest articles on DEV Community by Connor (@cgs-9).</description>
    <link>https://dev.to/cgs-9</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F4053938%2F5c97a5ed-0390-41eb-a736-bcac2a1e3b20.gif</url>
      <title>DEV Community: Connor</title>
      <link>https://dev.to/cgs-9</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/cgs-9"/>
    <language>en</language>
    <item>
      <title>DSA | Random Generator | Can you come up with a solution?</title>
      <dc:creator>Connor</dc:creator>
      <pubDate>Wed, 29 Jul 2026 23:08:03 +0000</pubDate>
      <link>https://dev.to/cgs-9/dsa-random-generator-can-you-come-up-with-a-solution-31gn</link>
      <guid>https://dev.to/cgs-9/dsa-random-generator-can-you-come-up-with-a-solution-31gn</guid>
      <description>&lt;p&gt;Hi, I may post some DSA / interview questions I find interesting (even if you would be unlikely to see it in an interview) from some of the books I own / codeforces / leetcode etc. &lt;/p&gt;

&lt;p&gt;This question comes from &lt;a href="https://www.worldofbooks.com/products/elements-of-programming-interviews-in-java-book-tsung-hsien-lee-9781517435806?sku=CIN1517435803VG&amp;amp;msclkid=f152658fe3a219ed6abb0fe560bb67d9&amp;amp;utm_source=bing&amp;amp;utm_medium=cpc&amp;amp;utm_campaign=Wob+-+USA+-+Bing+-+Pmax+-+CIN+-+EN+-+XX+-+Used+Books+-+SalesRank%3A+100001+-+500000+-+Feed+Only&amp;amp;utm_term=2323680387228935&amp;amp;utm_content=100001+-+500000" rel="noopener noreferrer"&gt;Elements of Programming Interviews in Java&lt;/a&gt; written by Lee, Aziz, and Prakash.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;4.10 Generate Random Uniform Numbers&lt;/strong&gt;&lt;br&gt;
How would you implement a random number generator that generates a random integer &lt;em&gt;i&lt;/em&gt; between &lt;em&gt;a&lt;/em&gt; and &lt;em&gt;b&lt;/em&gt; inclusive, given a random number generator that produces a zero or one with equal probability?&lt;br&gt;
ALL values in range [a,b] inclusive should be equally likely.&lt;/p&gt;

&lt;p&gt;&lt;em&gt;Hint Given&lt;/em&gt;: How would you mimic a three-sided coin with a two-sided coin?&lt;/p&gt;

&lt;p&gt;So you are given a 0/1 generator which gives you one of 0 or 1 at a 50% chance with each call to it: int zeroOrOne = generator().&lt;/p&gt;

&lt;p&gt;My &lt;em&gt;hint&lt;/em&gt; is this: What does &lt;em&gt;b - a&lt;/em&gt; represent, and how can you limit the number of calls to the generator?&lt;/p&gt;

&lt;p&gt;This is my first post!&lt;/p&gt;

</description>
      <category>leetcode</category>
      <category>algorithms</category>
      <category>interview</category>
      <category>probability</category>
    </item>
  </channel>
</rss>
