Scoop API

scoop:scoop.std:0.1.0

src/random/bounded.scoop

Selected production source · src/random/bounded.scoop

1package scoop.random
3internal fun sampleUInt(random: Random, span: UInt): UInt {
4 val threshold = (0u - span) % span
5 while (true) {
6 val value = random.nextUInt()
7 if (value >= threshold) return value % span
8 }
9}
11internal fun sampleULong(random: Random, span: ULong): ULong {
12 val threshold = (0uL - span) % span
13 while (true) {
14 val value = random.nextULong()
15 if (value >= threshold) return value % span
16 }