UniformInt

r.UniformInt(a,b)r.\operatorname{UniformInt}(a, b)

Generate a uniform random integer in [a,b)[a, b) using generator rr. This draw is derived from the underlying uniform float stream.

  • Range[a,b)[a, b) (includes aa, excludes bb)
  • ComplexityO(1)O(1) per draw

Example (conceptual)

  • CallRng(42).UniformInt(a, b) (conceptual name; see mapping below)
  • Range — integer in [0,100)[0, 100) or [50,50)[-50, 50)

Implementation names

LanguageMethod
C#UniformInt32() / UniformInt64() / UniformInt16() / UniformInt8()
GoUniformIntN() / UniformInt64() / UniformInt32() / UniformInt16() / UniformInt8()
KotlinuniformInt() / uniformLong() / uniformShort() / uniformByte()
Rustuniform_i32() / uniform_i64() / uniform_i16() / uniform_i8()
Pythonuniform_int()
Runiform_int()
TypeScriptuniformInt()

UniformInt\operatorname{UniformInt} draws are derived from the same generator core as UniformFloat\operatorname{UniformFloat} and map a uniform 64-bit value into [a,b)[a, b). The implementation uses modulo reduction; ranges that do not divide 2642^{64} introduce a slight bias (acceptable for simulation, not for cryptographic use). See UniformFloat → Algorithm for the core generator details.

Unsigned variants are available in languages that support them.