Every story and comment from the Hacker News API, in a layout borrowed from 2001.
A comment on My Job Interview at Google. Parent comment
First convert rand5() to rand2(). The LSB from rand5() has a uniform distribution for the integers 0--3:
int rand2() { int n = rand5(); return n!=4 ? n & 1 : rand2(); }
int rand7() { int n = rand2(); n |= rand2() << 1; n |= rand2() << 2; return n; }
There are no comments on this comment yet.
First convert rand5() to rand2(). The LSB from rand5() has a uniform distribution for the integers 0--3:
Now we simply build a three bit number: This gives the proper distribution as well, but it's not branch free, so really nothing new here.