Last active
August 19, 2023 08:44
-
-
Save PlaceReporter99/cf2e408d4c6fb666a2095f9da7db5b23 to your computer and use it in GitHub Desktop.
A PRNG algorithm I came up with.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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