Skip to content

Instantly share code, notes, and snippets.

@PlaceReporter99
Created August 20, 2023 17:27
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save PlaceReporter99/62f168a73217ce5b2cd91dde6dcbc5ed to your computer and use it in GitHub Desktop.
Save PlaceReporter99/62f168a73217ce5b2cd91dde6dcbc5ed to your computer and use it in GitHub Desktop.
A program that generates random numbers, which reseeds itself by querying the questions page on Stack Overflow, and hashing it. It might be cryptographically secure, it might not. I don't know.
import functools
import hashlib
import time
from urllib.request import urlopen
def so_reseed(func):
@functools.wraps(func)
def wrapper():
seed = hashlib.sha256(urlopen("https://stackoverflow.com/questions").read()).digest()[16]
while True:
i = func(seed)
yield next(i)
for _ in range(seed - 1):
time.sleep(0.5)
yield (b := next(i))
seed = hashlib.sha256(urlopen("https://stackoverflow.com/questions").read()).digest()[b % 32]
return wrapper
@so_reseed
def rand_hex(seed):
while True:
temp = int(time.time() % (7**seed))
seed = hashlib.sha256((str(temp)+str(time.time())).encode("utf-8")).digest()[temp % 32]
yield hashlib.sha256((str(seed)+str(time.time())).encode("utf-8")).digest()[temp % 32]
for x in rand_hex():
print(x)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment