LULUCID

4 developers (including me) decided to go out for dinner. They came up with 20 possible restaurants to go. I received a message which reads as follows:

Pick one of the 20 restaurants at random. And do so with 0 inputs from any of us. You should be able to prove that it's random.

The message was an email with all 4 developers in the loop. (Or a slack group where all 4 developers were part of it, Or WhatsApp group, anything really, **except that they are not all physically present at the same place**)

Constraints:

- It has to be truly random. For the scope of this post, we will assume truly random as follows: None of the 4 developers had any chance to influence the outcome, and from the perspective of those 4 developers it's totally random. (just use common sense here to say if something can be manipulated)
- You should not take additional inputs that would manipulate the result from any of the other developers (or) that are part of the decision process (Like asking for a seed number, etc)
- If need be, you should be able to prove that it was truly random.

Update: A lot of solutions proposed on reddit are missing constraint-2. The interesting part in this problem is that dev1 has to do it without inputs from other devs.

Sounds simple!!

Let's look at the most common ways to do this and why they all fail. These wrong solutions also give you an idea about what the real problem here is to solve.

**1)** I quickly opened up terminal, ran "echo $RANDOM" and responded to the message saying here is a random number, let's take modulo 20 to pick the restaurant. Wrong. This fails because there is no way to prove that it was indeed random. What if I picked a number of choice and responded? (So that I can go to my fav restaurant — I would do it :P)

**2)** I told each of the developers should run "echo $RANDOM" and then multiply them all. This does not work for 2 reasons: the last person to respond has full control of the outcome, he can multiply the 3 inputs and then decide his random number to manipulate the answer. And this also fails constraint-2.

**3)** I came up with a smart solution. I said, let's concat first names of all 4 developers in lexicographical order and then calculate md5 hash of that string. Then use that hash modulo 20. Nope, this does not work as well. Because it's me who came up with the idea to 'concat first names in lexicographical order'. What if I actually ran the md5 and checked that it's in my favor. I could have also checked for 'concat 4 last names', 'concat full names', 'concat birthdays'. You see there are a lot of different ways, and I may have tried all of them and picked the one that benefits me. Yet again, this fails constraint-3.

**4)** Here is another solution: we shall take the first 20 digits (since there are 20 restaurants) of PI and do modulo to get the solution. Okay, this got to work right? It's a universal constant, and 20 digits since we got 20 restaurants, I had no influence. Nope fails. Because once again like above case, I am the one who came up with the idea to use PI. What if I tried other universal constants and then chose PI as it is benefiting me?

Bring in your answers. There are no other constraints except the ones I told above — so go wild with your creativity. You can comment on the reddit thread below. If you want the solutions, they are available at the end of this post — collapsed. I am expecting many more solutions on the reddit thread (If the post gets noticed in the first place). reddit thread.

Update: You should check the reddit thread, it has some interesting discussions. And couple of new answers

Do you like problem solving & critical thinking? If so checkout this weekly newsletter.

A lil fun image :)