Live data from Hacker News

Ask HN: You're in an empty room. How do you generate a random number?

news.ycombinator.com

11–20 of 49 posts

Re: Ask HN: You're in an empty room. How do you generate a random number?

#11
Use all 8 directions (4 walls and 4 corners). Number them from 0 to 7 or 1 to 8. Pull out one hair with the root. Use that root as an arrow. Throw the hair and watch till it lands on the ground. Use the number that the root is pointing to. Repeat. For a better effect try to blow at the hair while in air so it spins more.

Re: Ask HN: You're in an empty room. How do you generate a random number?

#13
One standard trick that hasn't been mentioned: if you're e.g. looking at the ends of thrown undergarments, or at another random source that's guaranteed to produce uncorrelated output bits but is not guaranteed to produce a 0 with probability exactly 50% (e.g. an unbalanced undergarment), the following algorithm will yield uncorrelated outputs bits that are guaranteed to be 0 with probability exactly 50%:

- generate two bits

- if they are the same, discard both and start over

- if they are 0 1, return 0

- they are 1 0, return 1

Also, once you have generated some entropy using the above method, you can generate a much longer random-looking number using a (pseudo-)random number generator. You could use another of von Neumann's tricks, the middle-square method (http://en.wikipedia.org/wiki/Pseudorandom_number_generator#E...), if you're decent at arithmetic (and hey, any errors can be written off as a deliberate attempt to increase entropy); if you're really paranoid, you may want to try doing RC4, although I recommend smuggling in a pen for that.

That said, are you trying to solve some problem, or..?

Re: Ask HN: You're in an empty room. How do you generate a random number?

#14
- Put the undergarment somewhere in the room

- Divide the room in two: one half that contains the undergarment and the other half

- Go in the middle of the room

- Close your eyes and spin for a while. Then, count one if you are facing the part of the room that contains the undergarment and 0 otherwise

- Reiterate previous step as many times as necessary to build an integer (by binary writing).

Was this an interview question?

Re: Ask HN: You're in an empty room. How do you generate a random number?

#17
Assuming you wear light or silky undergarments and there is no constant air flow/current in the room:

1. Take off your undergarment. No one else is there, you don't need it anymore.

2. Tear apart your undergarment into as many small pieces as you can. Use your teeth if necessary. Let them dry to prevent clumping later. Make it an odd number to prevent you biasing the results, later.

3. Stand up straight. Place your feet together. Cup undergarment fragments in your hands at chest level.

4. Extend your arms, still cupping the fragments. Keep the center of your cupped hands on your plane of symmetry (in line with point at which your feet meet).

5. Drop fragments.

6. A. If more fragments land on the right side of the plane of symmetry, write 1.

6. B. If more fragments land on the left side of the plane of symmetry, write 0.

7. Repeat as many times as necessary for the number of random bits required.

Upside: you can do this in the dark (problem did not mention if a light source was readily available or not).

  -- e.w.t.

Re: Ask HN: You're in an empty room. How do you generate a random number?

#18

Take off your undergarment throw it by one wall. Assuming the room has 4 walls this is your marker for wall "0". The rest of the walls going counter-clockwise will be walls "1", "2" and "3". Close your eyes and spin in the room until you lose your orientation then stop and open your eyes. Record the number of the wall you are facing in your head. Repeat spin and remember next new number. Repeat spin and remember next…

This assumes that the number of times one can rotate before losing one's orientation is random. Presumably it is not only regular, but you might even get better as you practiced. Both of these would conspire to produce substantial autocorrelation in the generated series.

Re: Ask HN: You're in an empty room. How do you generate a random number?

#20
Divide room along one diagonal by urinating a rough line if bladder is full, or else cut your finger with your teeth and set the line that way. Similarly mark one side 'A' and the other side 'B.'

Remove undergarments and crumple into ball in both hands. Stand in what appears to be the center of the room. Select an unfamiliar song and spin around singing it with eyes closed until you can no longer remember any lyrics, at which point stop and use both hands to toss up the balled-up garment.

Open your eyes and search for the garment.

If the garment lands so that the 'front' appears to face up, append zero to the left of the number, else append one.

If garment lands in side A, flip all bits, and if garment lands in side B, flip only the bits of position equal to 1 mod c, (rightmost position called 0 for this purpose) where c is the value of the sub string of your current number generated from every third digit (positions 2, 5, and so on).

Repeat until the desired range is reached by the number of digits.

The method assumes that you have an incredible penchant for mental math.

Post reply on HN