Hello, is there a method to calculate a value betw...
# getting-started
d
Hello, is there a method to calculate a value between a range? Like if I want to get a value that is
X
or
min
or
max
, like:
X=50
,
min=0
,
max=40
, then the result is
40
I need this to calculate some positions, don't know if there's a method using
IntRange
r
Random.nextInt
can take a (min,max) or an IntRange
s
Maybe you want
coerceIn
?
Return this value if it's in the range, or
range.start
if this value is less than
range.start
, or
range.endInclusive
if this value is greater than
range.endInclusive
.
https://kotlinlang.org/api/latest/jvm/stdlib/kotlin.ranges/coerce-in.html
🙏 1
2
r
Not sure what's the purpose of
X
in your example 🤔
Ah yeah,
coerceIn
makes more sense, not sure where I got the idea you wanted a random value homer disappear
d
Thank you,
coerceIn
is the extension I was looking for