News for hackers. Stuff that matters.
Re:My Job Interview at Google by nostrademons on Monday November 24, 2008 @05:03PM (#375480)
That was my second thought too (my first thought was to upvote the comment), but at least in the 2-die case, the modulus takes care of it. If you work out the probabilities, the chance of getting 0mod2 = 1/36 (2) + 3/36 (4) + 5/36 (6) + 5/36 (8) + 3/36 (10) + 1/36 (12) = 18/36 = 1/2. Same goes for getting 1mod2. So you end up with a fair result even though the chances for each individual outcome are biased.

I didn't want to go through all 5^7 possibilities for the 7-die case, but I figured it's likely enough that he's right that I'd keep my mouth shut.

Re:My Job Interview at Google by llimllib on Monday November 24, 2008 @05:34PM (#375538)
experimental evidence says that it is in fact a uniform distribution:

  r = random.Random()

  def one_to_five():
    return r.randint(1, 5)

  def mod_seven():
    return (sum(one_to_five() for x in xrange(7)) % 7) + 1

  def test_dist(lst):
    return [(x, lst.count(x)) for x in [1,2,3,4,5,6,7]]
Re:My Job Interview at Google by sdfx on Monday November 24, 2008 @06:09PM (#375601)
i've tried it out experimentally in google docs and it looks really good for big numbers. No real proof tho and it might be that the errors counter each other by chance:

http://spreadsheets.google.com/ccc?key=pq4tB7LQWN03gF7ImGhIP...

Re:My Job Interview at Google by greendestiny on Monday November 24, 2008 @09:33PM (#375874)
Have a look at the distributions for each sum here: http://brianpmearns.com/ext/dice/dice.html

edit: Oops bad addition on my part, could be uniform, but you'd have to work out the actual number exactly.

Re:My Job Interview at Google by sdfx on Tuesday November 25, 2008 @07:18AM (#376280)
here are the exact numbers:

1 -> 11177

2 -> 11172

3 -> 11158

4 -> 11144

5 -> 11144

6 -> 11158

7 -> 11172

...not quite

Re:My Job Interview at Google by gaius on Tuesday November 25, 2008 @02:22AM (#376137)
I've done a lot of Python but never knew about xrange - thanks!