scoop:scoop.std:0.1.0
src/random/bounded.scoop
Selected production source · src/random/bounded.scoop
1
package scoop.random3
internal fun sampleUInt(random: Random, span: UInt): UInt {4
val threshold = (0u - span) % span5
while (true) {6
val value = random.nextUInt()7
if (value >= threshold) return value % span8
}9
}11
internal fun sampleULong(random: Random, span: ULong): ULong {12
val threshold = (0uL - span) % span13
while (true) {14
val value = random.nextULong()15
if (value >= threshold) return value % span16
}17
}