-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathsuper.py
119 lines (79 loc) · 2.97 KB
/
super.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
from time import time_ns as nanoseconds
## initialise the process, work out the numbers
## then update the random seed, return a floating result
## and do a nano hop.
def super_random(r=0) :
result=super_fast_random(r)
nano_hop()
return result
## this is the same as super_random()
## but without the hop delay.
def super_fast_random(r=0) :
global first, second, random_seed
normalisation()
new_seed=''
num1=0; num2=0; num3=0; num4=0; result='';
for f in range(0,8,1) :
num1=int(first[f])
num2=int(second[f])
if f>3 :
num3=int(random_seed[f-4])
num4=str(num1+num2+num3)
if int(num4)>9 :
if int(num4)>18 :
new_seed=new_seed+str(int(num4)-18)
else :
new_seed=new_seed+str(int(num4)-9)
else :
new_seed=new_seed+str(int(num4))[-1]
else :
num4=str(num1+num2)
result=result+num4[-1]
result=result+'.' ; result=float(result[-1:-10:-1])
feed_the_seed(new_seed)
if r>0 :
result=int(result*(r+1))
return result
## update or manually change the random seed.
def feed_the_seed(seed='1234') :
global random_seed
random_seed=seed
return
## find the reference points where the time varies.
def find_refs() :
global for_ref, back_ref, decimal_places
samp_zeros=0 ; sample_size=12
decimal_places=8
reference_length=len(str(nanoseconds()))
for samp_loops in range(sample_size) :
sample1=str(nanoseconds()); sample2=str(nanoseconds())
while sample1==sample2 :
sample2=str(nanoseconds())
sample2=sample2.rstrip('0')
samp_zeros=samp_zeros+(len(sample1)-len(sample2))
reference_zeros=int(samp_zeros/sample_size)
for_ref=reference_length-(decimal_places+reference_zeros)
back_ref=-(reference_zeros+decimal_places+1)
return
## ensures the timer has moved on since the last sample
## as possible to run many times in a nanosecond.
def nano_hop() :
sample1=str(nanoseconds()); sample2=str(nanoseconds())
while sample1==sample2 :
sample2=str(nanoseconds())
return
## make sure the numbers are in strings and padded with zeros.
def normalisation() :
global first, second, random_seed
first=str(nanoseconds())[for_ref:for_ref+decimal_places:1].zfill(8)
second=str(nanoseconds())[back_ref+decimal_places:back_ref:-1].zfill(8)
random_seed=str(random_seed).zfill(4)[0:4:1] #user seed string, padded to 4 zeros.
return
###########################################
## these run when the module is imported ##
###########################################
try : random_seed
except NameError : random_seed='1234'
try : for_ref
except NameError : find_refs()
###########################################