Skip to content

Modern Math NextBoolean

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

Home › Math Library › Math Library › NextBoolean

NextBoolean

Returns true or false with equal chance.

Syntax

NextBoolean( ) as boolean

Notes

  • One bit of the generator, not a comparison against 0.5 -- so it costs nothing extra and cannot be skewed by floating point.
  • NextBooleanP is the weighted version.

Examples

#import "std/numeric"
using numeric

dim r as Rng = RngFromEntropy( )

dim as int32 hits = 0
for i as int32 = 1 to 1000
    if r.NextBoolean( ) then hits += 1
next

print hits > 400 andalso hits < 600           '' -1 (true)

Library: Math Library
Category: Math Library
Documented under: Members

Clone this wiki locally