Web   ·   Wiki   ·   Activities   ·   Blog   ·   Lists   ·   Chat   ·   Meeting   ·   Bugs   ·   Git   ·   Translate   ·   Archive   ·   People   ·   Donate
summaryrefslogtreecommitdiffstats
path: root/common/Generation/Utils.py
diff options
context:
space:
mode:
authorAleksey Lim <alsroot@activitycentral.org>2011-02-28 16:13:13 (GMT)
committer Aleksey Lim <alsroot@activitycentral.org>2011-02-28 16:13:13 (GMT)
commita0705d8ff9b25c1172e38925ec27bb28f9e5a1e9 (patch)
treed3a20dff1d1e8d196fab33530fb21dd470addef5 /common/Generation/Utils.py
parent0c8e687ce284d7599b9bfb7c578b0fc7fb32c493 (diff)
Revert "fixing simlimking build error"
This reverts commit 0c8e687ce284d7599b9bfb7c578b0fc7fb32c493. Since common/ directory will be copied to .xo in setup.py anyway.
Diffstat (limited to 'common/Generation/Utils.py')
-rw-r--r--common/Generation/Utils.py74
1 files changed, 74 insertions, 0 deletions
diff --git a/common/Generation/Utils.py b/common/Generation/Utils.py
new file mode 100644
index 0000000..e5ea295
--- /dev/null
+++ b/common/Generation/Utils.py
@@ -0,0 +1,74 @@
+import random
+import time
+import math
+
+#----------------------------------------------------------------------
+# TODO: replace magic numbers with constants
+# http://en.wikipedia.org/wiki/Magic_number_(programming)
+#----------------------------------------------------------------------
+
+def prob(x):
+ sum1 = 0
+ sum2 = 0
+
+ for i in x:
+ sum1 = sum1 + i
+
+ val = sum1 * random.randint(0, 32767) / 32768
+
+ for i in range(len(x)):
+ sum2 = sum2 + x[i]
+ if x[i]:
+ if sum2 >= val:
+ return i
+ break
+
+def prob2(x):
+ sum1 = 0
+ sum2 = 0
+
+ for i in x:
+ sum1 = sum1 + i[1]
+
+ val = sum1 * random.randint(0, 32767) / 32768
+
+ for i in x:
+ sum2 = sum2 + i[1]
+ if i[1]:
+ if sum2 >= val:
+ return i[0]
+ break
+
+def scale(val, mini=0., maxi=1., length=100):
+ slope = []
+
+ up = 1.-val
+ if up <= 0.5:
+ low_val = (pow(1.-(up*2.),4.)*(-50.5)+0.5)
+ else:
+ low_val = up
+
+ if val <= 0.5:
+ high_val = (pow(1.-(val * 2.),4.)*(-50.5)+0.5)
+ else:
+ high_val = val
+
+ step = (maxi - mini) * (1. / length)
+
+ calc = (1. / length) * (high_val - low_val)
+ append = slope.append
+ for i in range(length + 1):
+ temp = i * calc + low_val
+ if temp < 0:
+ temp = 0
+ elif temp > 1:
+ temp = 1
+ else:
+ temp = temp
+
+ append(((step * i) + mini, int(temp * 100)))
+
+ return slope
+
+def midtotrans(x):
+ return pow(1.059463, x - 36)