Skip to content

Modern Math NextInt

Paul Squires edited this page Oct 19, 2026 · 6 revisions

Home › Math Library › Math Library › NextInt

NextInt

Returns a random whole number from lo to hi, both included, without bias.

Syntax

NextInt( lo, hi )

Notes

  • INCLUSIVE both ends, matching tiko's TO

Examples

#import "std/numeric"
using numeric

dim r as Rng = RngFromEntropy( )
dim as int64 lo = 1, hi = 6

'' INCLUSIVE at both ends, and UNBIASED -- it rejects and retries rather
'' than taking a modulus, which would favour the low end of the range
dim as int64 v = r.NextInt( lo, hi )
print v >= lo andalso v <= hi             '' -1 (true)

Library: Math Library
Category: Math Library
Documented under: Nothing Becomes A Keyword

Clone this wiki locally