W3cubDocs

/Kotlin

nextInt

Platform and version requirements: JVM (1.0), JS (1.0), Native (1.0)
fun nextInt(): Int

Gets the next random Int from the random number generator.

Generates an Int random value uniformly distributed between Int.MIN_VALUE and Int.MAX_VALUE (inclusive).

Platform and version requirements: JVM (1.0), JS (1.0), Native (1.0)
fun nextInt(until: Int): Int

Gets the next random non-negative Int from the random number generator less than the specified until bound.

Generates an Int random value uniformly distributed between 0 (inclusive) and the specified until bound (exclusive).

Parameters

until - must be positive.

Exceptions

IllegalArgumentException - if until is negative or zero.

Platform and version requirements: JVM (1.0), JS (1.0), Native (1.0)
fun nextInt(from: Int, until: Int): Int

Gets the next random Int from the random number generator in the specified range.

Generates an Int random value uniformly distributed between the specified from (inclusive) and until (exclusive) bounds.

Exceptions

IllegalArgumentException - if from is greater than or equal to until.

© 2010–2020 JetBrains s.r.o. and Kotlin Programming Language contributors
Licensed under the Apache License, Version 2.0.
https://kotlinlang.org/api/latest/jvm/stdlib/kotlin.random/-random/-default/next-int.html