commonMain.io.github.lyxnx.util.Random.kt Maven / Gradle / Ivy
The newest version!
package io.github.lyxnx.util
import kotlin.jvm.JvmSynthetic
import kotlin.random.Random
import kotlin.random.nextUInt
import kotlin.random.nextULong
// region Ints
/**
* Creates an infinite sequence of random integers with each value distributed between [Int.MIN_VALUE] (inclusive) and
* [Int.MAX_VALUE] (inclusive)
*
* @see Random.nextInt
*/
@JvmSynthetic
public fun Random.nextInts(): Sequence = generateSequence { nextInt() }
/**
* Creates a sequence of random integers with each value distributed between 0 (inclusive) and [until] (exclusive)
*/
@JvmSynthetic
public fun Random.nextInts(until: Int): Sequence = generateSequence { nextInt(until) }
/**
* Creates a sequence of random integers with each value distributed between [from] (inclusive) and [until] (exclusive)
*/
@JvmSynthetic
public fun Random.nextInts(from: Int, until: Int): Sequence = generateSequence { nextInt(from, until) }
// endregion
// region Doubles
/**
* Creates a sequence of random doubles with each value distributed between 0 (inclusive) and 1 (exclusive)
*
* @see Random.nextDouble
*/
@JvmSynthetic
public fun Random.nextDoubles(): Sequence = generateSequence { nextDouble() }
/**
* Creates a sequence of random doubles with each value distributed between 0 (inclusive) and [until] (exclusive)
*/
@JvmSynthetic
public fun Random.nextDoubles(until: Double): Sequence = generateSequence { nextDouble(until) }
/**
* Creates a sequence of random doubles with each value distributed between [from] (inclusive) and [until] (exclusive)
*/
@JvmSynthetic
public fun Random.nextDoubles(from: Double, until: Double): Sequence =
generateSequence { nextDouble(from, until) }
// endregion
// region Floats
/**
* Creates a sequence of random float with each value distributed between 0 (inclusive) and 1 (exclusive)
*
* @see Random.nextFloat
*/
@JvmSynthetic
public fun Random.nextFloats(): Sequence = generateSequence { nextFloat() }
// endregion
// region Longs
/**
* Creates a sequence of random longs with each value distributed between [Long.MIN_VALUE] (inclusive) and
* [Long.MAX_VALUE] (inclusive)
*
* @see Random.nextLong
*/
@JvmSynthetic
public fun Random.nextLongs(): Sequence = generateSequence { nextLong() }
/**
* Creates a sequence of random longs with each value distributed between 0 (inclusive) and [until] (exclusive)
*/
@JvmSynthetic
public fun Random.nextLongs(until: Long): Sequence = generateSequence { nextLong(until) }
/**
* Creates a sequence of random longs with each value distributed between [from] (inclusive) and [until] (exclusive)
*/
@JvmSynthetic
public fun Random.nextLongs(from: Long, until: Long): Sequence = generateSequence { nextLong(from, until) }
// endregion
// region Booleans
/**
* Creates an infinite sequence of random booleans
*/
@JvmSynthetic
public fun Random.nextBooleans(): Sequence = generateSequence { nextBoolean() }
// endregion
// region UInts
/**
* Creates a sequence of random unsigned integers with each value distributed between [UInt.MIN_VALUE] (inclusive) and
* [UInt.MAX_VALUE] (inclusive)
*
* @see Random.nextUInt
*/
@JvmSynthetic
public fun Random.nextUInts(): Sequence = generateSequence { nextUInt() }
/**
* Creates a sequence of random unsigned integers with each value distributed between 0 (inclusive) and [until] (exclusive)
*/
@JvmSynthetic
public fun Random.nextUInts(until: UInt): Sequence = generateSequence { nextUInt(until) }
/**
* Creates a sequence of random unsigned integers with each value distributed between [from] (inclusive) and [until]
* (exclusive)
*/
@JvmSynthetic
public fun Random.nextUInts(from: UInt, until: UInt): Sequence = generateSequence { nextUInt(from, until) }
// endregion
// region ULongs
/**
* Creates a sequence of random unsigned longs with each value distributed between [ULong.MIN_VALUE] (inclusive) and
* [ULong.MAX_VALUE] (inclusive)
*
* @see Random.nextULong
*/
@JvmSynthetic
public fun Random.nextULongs(): Sequence = generateSequence { nextULong() }
/**
* Creates a sequence of random unsigned longs with each value distributed between 0 (inclusive) and [until] (exclusive)
*/
@JvmSynthetic
public fun Random.nextULongs(until: ULong): Sequence = generateSequence { nextULong(until) }
/**
* Creates a sequence of random unsigned longs with each value distributed between [from] (inclusive) and [until] (exclusive)
*/
@JvmSynthetic
public fun Random.nextULongs(from: ULong, until: ULong): Sequence = generateSequence { nextULong(from, until) }
// endregion