Created
January 21, 2018 06:01
-
-
Save dimritium/32d30860469b049161718d7665e9111f to your computer and use it in GitHub Desktop.
syntax explanation
This file contains 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
from time import time | |
# importing from time module, python inbuilt module | |
import time as t | |
# a shorthand for time so that only t can be used instead of time | |
def get_seeds(): # a fxn to get seeds | |
value_1 = value_2 = 0 | |
while not value_1 and not value_2: | |
#print int(str(time() - int(time()))[-1]), int(str(time() - int(time()))[-2]) | |
try: # try catch is try except in python | |
value_1, value_2 = int(str(time() - int(time()))[-1]), int(str(time() - int(time()))[-2]) | |
# here we are calculating two values separated by comma eg a, b = 4, 5 (4 assigned to a and 5 to b) | |
except ValueError: # valueError will be catched or in python terms except | |
get_seeds() | |
# function call | |
return value_1, value_2 # we are returning two values | |
# ensure relationship of seeds fits that of an lcg and return the "random" result | |
def validate_inputs(modulus, increment): | |
relation = 0 | |
while not relation: # as long as relation is false this will run | |
multiplier, seed = get_seeds() # get_seed() will return two values and multiplier and seed will get those | |
# check validity of relation | |
relation = 0 <= increment < modulus and 0 <= seed < modulus and multiplier in [1, 3, 7, 9] | |
# this is checking relation on conditions eg multiplier be 5 then -> multiplier in [1, 3, 7, 9] -> return false | |
return multiplier, seed # two values being returned | |
# main function | |
def generate(modulus, increment): | |
multiplier, seed = validate_inputs(modulus, increment) | |
output = [seed] # this is a list in python denoted by [] with initial item being seed only | |
current_iteration = -1 | |
switch = False | |
while current_iteration != seed and current_iteration != 0: | |
if not switch: # if switch is false the if block will run | |
current_iteration = (seed * multiplier) + increment | |
switch = True | |
else: | |
current_iteration = (current_iteration * multiplier) + increment | |
if current_iteration > modulus: | |
current_iteration %= modulus | |
output.append(current_iteration) # python method append to insert current_iteration value in output list | |
result = int(str(''.join([str(i) for i in output]))[-1]) # here join is a python method and it joins an array or list based on value before . | |
return result | |
start=t.ctime().split(" ")[3] # t.ctime().split(" ") will split at space and return a list so [3] at end means item at index 3 | |
maxlist=[] #python list initialy empty | |
minlist=[] | |
m=10 | |
i=0 | |
loop=True | |
times=100 | |
while loop: | |
t.sleep(0.00000000000001) | |
num=generate(m,i) | |
#print num | |
if num >= 5: | |
if len(maxlist)<73: | |
maxlist.append(num) # python list method to add elements | |
else: | |
if len(minlist)<27: | |
minlist.append(num) | |
if len(maxlist)==73 and len(minlist)==27: # len(maxlist) will return length of list | |
loop=False | |
end=t.ctime().split(" ")[3] # explained above | |
print(start,end) # will print two variables separated by space on terminal | |
print(len(minlist),len(maxlist)) | |
print(minlist) | |
print(maxlist) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment