Ask HN: You're in an empty room. How do you generate a random number?
The only thing you're wearing is 1 undergarment. The room has no windows, doors or any objects inside it.
How do you generate the "most random" number you can using only what you can in your means.
48 comments
[ 4.1 ms ] story [ 92.4 ms ] thread0) remove undergarment (I'm assuming a bra because it's simplest, but the same principle applies to other varieties) 1) scratch your arm until you bleed 2) mark one cup of the bra with blood (both inside and outside) 3) stand against a wall 4) set i <- 0, n <- 0 5) throw bra up into the air, spinning it in the plane parallel to the floor 6) observe which cup is closer to the wall (if unclear, goto 5) 7) set x <- 0 if clean, 1 if bloody 8) if i >= floor(log2(k)), goto 11 9) set n <- n + (2i)*x 10) set i <- i + 1, goto 5 11) if n > k, goto 4 12) your number is n.
If it's hot out, I remove the undergarment.
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 new number.
Repeat, repeat, repeat until you have reached the maximum amount of numbers you can remember sequentially. You will have a sequence like 2,1,3,0,2.
Take your numbers, concatenate them sequentially, and translate from base 4 (ex. 21302) to base 10 (ex. 626)
- 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..?
- 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?
http://dilbert.com/strips/comic/2001-10-25/
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).
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.
Is the empty room inside e.g: a space station or a rocket? Am I a robot or an alien? Does the undergarment contain any wearable electronics with an antenna?
So let's say I'm an alien with an ability to detect the state of my antenna in my undergarment. I'll just occasionally check the level of a very high frequency electromagnetic wave in the antenna and occasionally write down the last significant digit of the output. no problem. ;)
To expand on the range do this another set of times, except this time take the sum (no average) and use this as the exponent.
Congratulations, you have successfully generated a random number using only your finger, fecal matter, and a little bit of math.
Now sit in this room of solitude until you die or are released from Guantanamo Bay.
Use it to generate a number. Try to say it in English and fail because you only speak Simanese.
If your room is large enough choose a random path from one wall to another. Take small steps by placing one foot directly in front of the other. Count the number of steps mod a small number.
2. lay out the threads
3. define distances between them to either be "big" or "small". proportion them better so that all the "big" distances are roughly the same size as each other, and do so for the smaller distances as well so there's no confusion as to which is big, and which is small.
4. assign a "1" to the "big" distances, and a "0" to the "small" distances, similar to how a barcode works.
5. you now have a binary number which contains as many bits as there are spaces between the individual threads (quite large!).
you can generate 2^n-1 random numbers in this fashion, where n is the number of threads in the undergarment.