Skip to content

Instantly share code, notes, and snippets.

@PlaceReporter99
Last active August 19, 2023 08:44
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save PlaceReporter99/cf2e408d4c6fb666a2095f9da7db5b23 to your computer and use it in GitHub Desktop.
Save PlaceReporter99/cf2e408d4c6fb666a2095f9da7db5b23 to your computer and use it in GitHub Desktop.
A PRNG algorithm I came up with.
def square_minus(seed: int, exponent: float = 2, modulo: float = float('inf')) -> iter:
"""
This function will return a generator function that can be iterated over infinitely.
We square the number and then remove the digits from the square number that are in the original. This will be the new number.
If no digits are left, it does the same process for the next number up.
"""
start = seed
while True:
setseed_2 = [*str(start**exponent)]
reg_seed = [*str(start)]
for x in reg_seed:
while True:
try:
setseed_2.remove(x)
except ValueError:
break
try:
start = int(int(''.join(setseed_2)) % modulo)
except ValueError:
try:
start = next(square_minus(start + 1, exponent, modulo))
except RecursionError: # We don't want a recursion error, so we just keep going.
start = next(square_minus(start + 1, exponent, modulo))
yield start
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment