For my birthday, my brother-in-law gave me a 4992-digit hex number that, when used as a seed for Python’s random number generator, makes it so that printing a sequence of “random” ASCII characters actually prints a birthday greeting.
-
@robinhouston Super cool! I guess this is only possible because the Mersenne Twister has such a huge state space (2 kB), making it likely that a valid seed exists. I think e.g. the PCG64 generator has only 128 bits of state, so any requested output of that length or longer would not likely be reproducible.
@thomastc @robinhouston It’s only likely that a valid seed exists when using a large internal state, but it’s a little surprising that the process is reversible, because brute force search across seeds would be infeasible.
-
For my birthday, my brother-in-law gave me a 4992-digit hex number that, when used as a seed for Python’s random number generator, makes it so that printing a sequence of “random” ASCII characters actually prints a birthday greeting.
I find it rather amazing that this is possible!
This is the program he sent with the seed:
with open("seed.txt", encoding="ascii") as handle:
seed = int(handle.read().strip(), 0)
r = random.Random(seed)
pending = ""
while True:
character = chr(r.randrange(128))
if pending + character == "\x1e\x1f":
break
print(pending, end="")
pending = character
print()@robinhouston If I stare at it long enough, will my birthdays reverse?.. cuz I'm feelin' pretty freakin' old...
-
@thomastc @robinhouston It’s only likely that a valid seed exists when using a large internal state, but it’s a little surprising that the process is reversible, because brute force search across seeds would be infeasible.
@Colinvparker @thomastc @robinhouston the trick is that, if only a few bits of the output are constrained, then you only have to solve for a state sequence that produces the right constrained bits, and the other bits are free to change. that reduces the complexity of the maths a lot.
-
For my birthday, my brother-in-law gave me a 4992-digit hex number that, when used as a seed for Python’s random number generator, makes it so that printing a sequence of “random” ASCII characters actually prints a birthday greeting.
I find it rather amazing that this is possible!
This is the program he sent with the seed:
with open("seed.txt", encoding="ascii") as handle:
seed = int(handle.read().strip(), 0)
r = random.Random(seed)
pending = ""
while True:
character = chr(r.randrange(128))
if pending + character == "\x1e\x1f":
break
print(pending, end="")
pending = character
print()@robinhouston This sounds like a bigger problem.
-
He's just confessed how he did it!
@robinhouston someone needs to make a quine out of this!
-
He's just confessed how he did it!
@robinhouston oh hey, he supervised one of my projects last year!
-
For my birthday, my brother-in-law gave me a 4992-digit hex number that, when used as a seed for Python’s random number generator, makes it so that printing a sequence of “random” ASCII characters actually prints a birthday greeting.
I find it rather amazing that this is possible!
This is the program he sent with the seed:
with open("seed.txt", encoding="ascii") as handle:
seed = int(handle.read().strip(), 0)
r = random.Random(seed)
pending = ""
while True:
character = chr(r.randrange(128))
if pending + character == "\x1e\x1f":
break
print(pending, end="")
pending = character
print()@robinhouston Ably demonstrating that machine "randomisation", isn't.
-
For my birthday, my brother-in-law gave me a 4992-digit hex number that, when used as a seed for Python’s random number generator, makes it so that printing a sequence of “random” ASCII characters actually prints a birthday greeting.
I find it rather amazing that this is possible!
This is the program he sent with the seed:
with open("seed.txt", encoding="ascii") as handle:
seed = int(handle.read().strip(), 0)
r = random.Random(seed)
pending = ""
while True:
character = chr(r.randrange(128))
if pending + character == "\x1e\x1f":
break
print(pending, end="")
pending = character
print()@robinhouston can you all stop boosting this wonderful thing so that I can send a version of it to my friend for his birthday?
-
For my birthday, my brother-in-law gave me a 4992-digit hex number that, when used as a seed for Python’s random number generator, makes it so that printing a sequence of “random” ASCII characters actually prints a birthday greeting.
I find it rather amazing that this is possible!
This is the program he sent with the seed:
with open("seed.txt", encoding="ascii") as handle:
seed = int(handle.read().strip(), 0)
r = random.Random(seed)
pending = ""
while True:
character = chr(r.randrange(128))
if pending + character == "\x1e\x1f":
break
print(pending, end="")
pending = character
print()@robinhouston A million monkeys writing Python will eventually write Happy Birthday! I love it!
Happy Birthday!
-
For my birthday, my brother-in-law gave me a 4992-digit hex number that, when used as a seed for Python’s random number generator, makes it so that printing a sequence of “random” ASCII characters actually prints a birthday greeting.
I find it rather amazing that this is possible!
This is the program he sent with the seed:
with open("seed.txt", encoding="ascii") as handle:
seed = int(handle.read().strip(), 0)
r = random.Random(seed)
pending = ""
while True:
character = chr(r.randrange(128))
if pending + character == "\x1e\x1f":
break
print(pending, end="")
pending = character
print()@robinhouston a bit like Tristan Miller's very silly "The Great Commodore/Microsoft Easter
Egg War" from 2015, which claims there are secret messages encoded in Commodore BASIC's RND() function ...
https://www.tpug.ca/tpug-media/nl/91-Fall2015.pdf#page=7 -
He's just confessed how he did it!
@robinhouston Very cool! If he enjoyed that, he would probably enjoy this as well - I fell into a similar rabbit hole with Python hashing

https://www.leeholmes.com/efficiently-generating-python-hash-collisions/
-
N niels@social.data.coop shared this topic