Random Hello World

A question on StackOverflow asks how two calls to random can print Hello World? The answer, there's lots of information in those seeds. webpage

The program in question is as follows.

System.out.println( randomString(-229985452) + " " + randomString(-147909649) );

The function randomString calls the system random number generator asking for a number between 0 and 26 until 0 is returned. 1 through 26 are converted to letters to be returned as a string.

The function randomString begins by initializing the random number generator to the specified seed. Apparently the first seed sets the sequence to a position in the random sequence where H E L L O in radix 26 follows. The second sequence must be W O R L D.

Psudorandom

The java random number generator uses the property of numbers to generate a long sequence with useful, random-like properties. When we 'seed' the generator we are choosing a starting point in that sequence.

When we want the random-like properties in a repeatable sequence we have only to seed the generator with the same seed over and over.

The author of the above program must have searched the java generator's sequence for the desired letters. That may have taken some time. Who knows? But with known seeds the generator spells the same way every time.

Your Name

Is your name in the java random number sequence? I don't know. You will have to look. But the generated sequence does not go on forever without repeating. When it starts repeating, look no further.

We can estimate the length of the sequence by considering how much state the generator keeps from call to call. If it is 32 bits of state, then there are only 2^32 possible starting points.

Its known that π does not repeat and appears random. Is your name spelled out in the digits of π or any other irrational number? Maybe, maybe not.

It is possible to go on forever without repeat and still not visit every letter you need to spell your name. We can Ask a Mathematician. webpage