Ask HN: You're in an empty room. How do you generate a random number?
11–20 of 49 posts
Re: Ask HN: You're in an empty room. How do you generate a random number?
#12Re: Ask HN: You're in an empty room. How do you generate a random number?
#13- 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- 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?
#15Re: Ask HN: You're in an empty room. How do you generate a random number?
#16Re: Ask HN: You're in an empty room. How do you generate a random number?
#171. 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?
#18Take 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…
Re: Ask HN: You're in an empty room. How do you generate a random number?
#19That's easy. I just say to myself, "Think of a random number between 1 and X.", and then I do. I see magicians do this all the time. If it's hot out, I remove the undergarment.
Re: Ask HN: You're in an empty room. How do you generate a random number?
#20Remove 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.