Browse Source

Enhancement in random value generators

Yann Weber 6 years ago
parent
commit
d3501926b1
2 changed files with 9 additions and 2 deletions
  1. 4
    1
      gte/mutator.py
  2. 5
    1
      gte/rpnlib.py

+ 4
- 1
gte/mutator.py View File

@@ -66,5 +66,8 @@ def mutupdtype(expr):
66 66
 
67 67
 def mutupdval(expr):
68 68
     pos = randint(0, len(expr) - 1)
69
-    expr[pos] = RpnSymbol(randint(0, 0xFFFF), expr[pos].optype)
69
+    if expr[pos].optype == RpnSymbol.VALUE:
70
+        expr[pos] = RpnSymbol.rand_value()
71
+    else:
72
+        expr[pos] = RpnSymbol(randint(0, 0xFFFF), expr[pos].optype)
70 73
     return expr

+ 5
- 1
gte/rpnlib.py View File

@@ -192,7 +192,11 @@ class RpnSymbol(object):
192 192
         if optype is None:
193 193
             optype = [cls.OPERATION, cls.VALUE, cls.VARIABLE]
194 194
             optype = optype[random.randint(0,2)]
195
-        return cls(random.randint(0, 0xFFFF), optype)
195
+        if optype == cls.VALUE:
196
+            vals = [(0,0xF), (0, 0xFF), (0,0xFFFF)]
197
+            return cls(random.randint(*vals[random.randint(0,2)]), optype)
198
+        else:
199
+            return cls(random.randint(0, 0xFFFF), optype)
196 200
 
197 201
     @classmethod
198 202
     def rand_op(cls):

Loading…
Cancel
Save