Randomization not working reliably for floats

This commit is contained in:
Dominik Moritz Roth 2023-01-06 17:23:58 +01:00
parent d8e7c4c80f
commit e0f4aa3c13

View File

@ -564,14 +564,16 @@ class ColumbusConfigDefined(ColumbusEnv):
else: else:
v = v_raw v = v_raw
if k.endswith('_rand'): if k.endswith('_rand'):
print('_rand!')
if isinstance(v, int): if isinstance(v, int):
print('int!')
n = k.replace('_rand', '') n = k.replace('_rand', '')
cur = getattr( cur = getattr(
entity, n) entity, n)
inc = int((v+0.99)*self.random()) inc = int((v+0.99)*self.random())
setattr(entity, n, cur + inc) setattr(entity, n, cur + inc)
elif isinstance(v, float): elif isinstance(v, float):
n = k.replace('_randf', '') n = k.replace('_rand', '')
cur = getattr( cur = getattr(
entity, n) entity, n)
inc = v*self.random() inc = v*self.random()
@ -585,7 +587,7 @@ class ColumbusConfigDefined(ColumbusEnv):
cur[vi] = int((v+0.99)*self.random()) cur[vi] = int((v+0.99)*self.random())
setattr(entity, n, cur) setattr(entity, n, cur)
elif isinstance(v, float): elif isinstance(v, float):
n = k.replace('_randf', '') n = k.replace('_rand', '')
cur = getattr( cur = getattr(
entity, n) entity, n)
cur[vi] = v*self.random() cur[vi] = v*self.random()