java - How to clamp a value from 0 to infinite to a value from 0 to 1? -
i have program in java generates float value aggressiveness can 0 infinite. need higher float is, higher there chances program fires function attackpawn().
i found out need function math.random(), gives random value between 0 , 1. if math.random() lower aggressiveness transformed float between 0 , 1, call function attackpawn().
but stuck, can't figure out how can transform aggressiveness 0 infinite float 0 1, 1 meaning "infinite" aggressiveness , 0 meaning absence of anger.
any ideas or maths equation ? thank in advance
you want monotonic function maps [0...infinity] [0..1]. there many options:
y=math.atan(x)/(math.pi/2); y=x/(1+x); y=1-math.exp(-x); there more. , each of functions can scaled arbitrarily, given positive constant k>0:
y=math.atan(k*x)/(math.pi/2); y=x/(k+x); y=1-math.exp(-k*x); there infinite number of options. pick 1 suits needs.
Comments
Post a Comment