-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbrown.py
33 lines (28 loc) · 907 Bytes
/
brown.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
import random
import itertools
class brown_data:
def __init__(self, scale=1, max_change=0.1):
self.num = None
self.scale = scale
self.max_change = max_change
def random(self):
if self.num is not None:
self.num = self.next()
return self.num
else:
factor = self.scale * 2
self.num = (random.random() * factor) - self.scale
return self.num
def next(self):
factor = self.max_change * 2
difference = self.max_change - (random.random() * factor)
newNum = self.num + difference
if newNum < -self.scale or newNum > self.scale:
self.num = self.num - difference
else:
self.num = newNum
return self.num
if(__name__ == "__main__"):
test = brown_data(10)
for _ in itertools.repeat(None, 2000):
print(test.random())