def __generateRandomVarValue(cls, iVar):
# 1- Get the definition domain of the variable
defDomain = cls.VARIABLES_RANGES[iVar]
if defDomain is None:
randFloat = random.uniform(-sys.maxint-1, sys.maxint)
else:
# 2- Check the open/closed bounds
includeFirst = defDomain[0] == '['
includeLast = defDomain[-1] == ']'
# 3- Get a random number in the domain
defDomain = eval('[' + defDomain[1:-1] + ']')
randFloat = random.random()*(defDomain[1]-defDomain[0]) + defDomain[0]
# 4- Check the bounds
while (randFloat == defDomain[0] and not includeFirst) or\
(randFloat == defDomain[1] and not includeLast):
randFloat = random.random()*(defDomain[1]-defDomain[0]) + defDomain[0]
# 5- Cast the variable type
return cls.VARIABLES_TYPE(randFloat)
# ----------------------
评论列表
文章目录