Hacker News new | past | comments | ask | show | jobs | submit login

When I was little (and had too much free time) I memorized many digits of some transcendental numbers. The only (semi)practical use I've found for that knowledge, is that I can use it as a reasonably good pseudorandom stream. If for some reason I have to choose things pseudorandomly. Pick an arbitrary starting point in pi, and press 'd' for even digits and 'f' for odd digits, I get around 0.49 accuracy with this oracle.



You don't need a transcendental number; simple counting has perfect entropy:

0 1 10 11 100 101 110 111 1000 1001 1010 1011 1100 1101 1110 1111 10000...

(Granted, that is a transcendental number -- the Champernowne constant for base 2 -- but there's no real need to think of it that way.)


This sequence seems to settle right around 50%:

  var simulateKeyPress = function(character) {
    var evt = document.createEvent("KeyboardEvent");
    evt.initKeyEvent ("keypress", true, true, window,
                      0, 0, 0, 0,
                      0, character.charCodeAt(0)) 
    document.body.dispatchEvent(evt);
  };
  
  var num = 0;
  var loop = function() {
    console.log(num);
    var binary = num.toString(2);
    num++;
    for(var i = 0, len = binary.length; i < len; i++) {
      simulateKeyPress(binary[i] == '0' ? 'd' : 'f');
    }
  };
  
  setInterval(loop, 100);


It might sound weird, but I actually found that more readable as three lines of code. :/


I wrote a program that counts but only appends the sequence if the binary sequence isn't already there.


> but only appends the sequence if the binary sequence isn't already there

Why?


Haha, I did the same thing! From memory:

3.141592653589793238462643383279502884197969399375105

Now, the interesting question, how accurate is my recollection after all these years? Ack, one digit off!


If a transcendental number is imperfectly remembered, are its digits thereby less random?


More random, I'd say.


141592653589793238462643383279502884197969399375105... that 9 should be a 1, right?


Indeed.


Mm I did something similar, doesn't need memorization though: arbitrarily form sentences, go through the letters in order, and pick 'd' for a-m and 'f' for n-z. Of course there will be some patterns, but it's sufficient for this. And I think this strategy uses more free will :P


I imagined how I would have coded it and so I devised a system to get it down as low as possible. I ended up with 0.44 accuracy. Pure random would have been better :)


Well, that only shows that this oracle can be improved. It should be able to recognize that pattern from a well known transcendental number.


That might be a slippery slope though. Is a known random sequence less random than an original one? Should a randomness detector keep a database of all random sequence ever produced to give lower scores to known ones?


but what if the challenge was not 2 chars but 3 (d, e, f)?

pi (base 9) = 3.12418812407442788645177761731035828516545353462652301126321450283864034354163303086781327...




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: