Ask HN: You're in an empty room. How do you generate a random number?
How do you generate the "most random" number you can using only what you can in your means.
How do you generate the "most random" number you can using only what you can in your means.
- 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..?
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)
0) 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.
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.
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.Then, wrap the thread around your roundest finger or other body part as many times as it will go. It should be possible to tell what quadrant was reached by the end of the thread. E.g., if it ended up closest to the top of your chosen body part, that's 00, the right side is 01, the bottom is 10, and the left side is 11.
That's two bits of reasonably-good entropy per thread. Repeat until your underwear is gone or you have the desired number of digits.
Another idea: spit on the wall and count the number of heartbeats it takes for the spit to run down to the floor.
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.
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. ;)
If all you need to do is pick one random number, just pick one: 0 or 1. That will be to any level of proof just as random as any natural method one could devise for a single number.
If instead the question is about generating a series of digits, and making an argument about the randomness of thosee digits, that is a completely different problem, and one that needs more specification about how much random data is needed and what context against which that randomness will be evaluated.
- 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?
For a normally distributed series of numbers make a jump and report the length (in milimeters). You will produce a series normally distributed around your average jumping length.
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.
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.