We know that our physical world is deterministic (and please, don’t come with the Dr Quantum videos of YouTube, by more strange and successful that the QM laws are, they do not fully represent a solid understand, and there are still many gaps to be filled), which means that creating a TRUE random number generator it’s impossible. Some people uses atmospheric noise to create random numbers, but it’s just a hard-to-predict approach and not a TRUE random number generator, there are some people using the radioactive decay too, but it can still be just a unknow mechanism. When I say by “TRUE”, I’m talking about a number that is created by something that could break the causality law, something that have an effect without prior cause. So, I think, the secret for creating a True Random Number Generator (TRNG) instead of a Pseudo-Random Number Generator (PRNG) is to link our generator with the only thing that is supposed to break the causality law: us.

We have two possibilities, the first, is that we have free will and the other is that we are predetermined since the begin (if it had a begin) of the world or even before. So, if we have a free will, we must have in some way, to break the causality law, otherwise, it is impossible to have a free will if we follow the causality law. So, any RNG which is linked with a human created content is, philosophically, linked with our free will too.

But, how can we create Random Numbers using a user generated content ? Well, one way is to use Twitter Public Timeline to create random data, since it’s a random stream of data which is linked with our free will, we can use other stream of user created data, but for sake of simplicity I’ve used Twitter Public Timeline =)

So, what I’ve done was: subclassed the Python Mersenne Twister random number generator to get the Twitter Public Timeline and then reseed the Mersenne Twister in every call of the random() method. Here is the source-code:

?View Code PYTHON
 ```import random import time import twitter   class TwitterRandom(random.Random): TOO_SOON = 1 ITS_OK = 0 TWITTER_CACHE_TIME = 65   def __init__(self, seed_value=None): random.Random.__init__(self, seed_value) self.twitter_api = twitter.Api() self.twitter_data = [] self.last_time = time.time() self.load_twitter_data(False)   def random(self): if len(self.twitter_data) <= 0: if self.load_twitter_data() != self.ITS_OK: return random.Random.random(self)   self.seed(self.twitter_data.pop()) return random.Random.random(self)   def load_twitter_data(self, check_time=True): if check_time: if (time.time() - self.last_time) <= self.TWITTER_CACHE_TIME: return self.TOO_SOON data = self.twitter_api.GetPublicTimeline() for status in data: vals = [ord(v) for v in status.text] self.twitter_data.extend(vals) return self.ITS_OK   def run_main(): true_random = TwitterRandom() random_numbers = [true_random.randint(0,100) for i in xrange(10)] print random_numbers   if __name__ == "__main__": run_main()```

Unfortunatelly, Twitter caches the Public Timeline for 60 seconds, so when using the Random Number Generator, it can run out of user created data.

And of course, this is just a philosophical speculation, based on the fact that our intuition says that it’s more possible to have free will and something breaking the law of causality in ourselves instead of in a radioactive decay or in the world outside us, since we’ve never saw something breaking the law of causality in the external world.

If you enjoyed this post, please consider leaving a comment or subscribing to the RSS feed to have future articles delivered to your feed reader.