BlitzMax

BlitzMax

  • Downloads
  • Docs
  • API
  • Resources
  • About

›Core

BlitzMax API

  • Introduction

BRL

    Audio

    • Introduction
    • TChannel
    • TSound

    AudioSample

    • Introduction
    • TAudioSample
    • TAudioSampleLoader

    Bank

    • Introduction
    • TBank

    BankStream

    • Introduction
    • TBankStream

    Base64

    • Introduction
    • TBase64

    Blitz

    • Introduction
    • TArrayBoundsException
    • TBlitzException
    • TIllegalArgumentException
    • TInvalidEnumException
    • TNullFunctionException
    • TNullMethodException
    • TNullObjectException
    • TOutOfDataException
    • TRuntimeException
    • IIterable
    • IIterator
    • ICloseable

    Clipboard

    • Introduction
    • TClipboard
    • TClipboardOpts
    • TWin32ClipboardOpts
    • TX11ClipboardOpts

    Color

    • Introduction
    • SColor8
  • BRL.D3D7Max2D
  • BRL.D3D9Max2D
  • BRL.DirectSoundAudio
  • BRL.EndianStream
  • Event

    • Introduction
    • TEvent
  • BRL.EventQueue
  • FileSystem

    • Introduction
    • IFileWalker
    • SFileAttributes
  • BRL.FreeAudioAudio
  • BRL.GLGraphics
  • BRL.GLMax2D
  • Glob

    • Introduction
    • EGlobOptions
    • TGlobIter
  • BRL.GNet
  • BRL.Graphics
  • BRL.Hook
  • IO

    • Introduction
    • MaxIO
  • BRL.KeyCodes
  • LinkedList

    • Introduction
    • TList
    • TListEnum
    • TLink

    Map

    • Introduction
    • TMap
  • BRL.Math
  • Max2D

    • Introduction
    • TImage

    MaxLua

    • Introduction
    • TLuaClass
    • TLuaObject

    MaxUnit

    • Introduction
    • TTest
    • TAssert
  • BRL.OGGLoader
  • BRL.OpenALAudio
  • Path

    • Introduction
    • TPath
    • IPathWalker
    • SPathAttributes
    • TPathDirIterator

    Pixmap

    • Introduction
    • TPixmap
    • TPixmapLoader
  • BRL.PolledInput
  • BRL.RamStream
  • Random

    • Introduction
    • TRandomDefault

    RectPacker

    • Introduction
    • EPackingMethod
    • SPackedRect
    • TPackedSheet
    • TRectPacker

    Reflection

    • Introduction
    • TTypeId
    • TMember
    • TConstant
    • TField
    • TGlobal
    • TFunction
    • TMethod
  • BRL.Retro
  • BRL.Socket
  • BRL.SocketStream
  • BRL.StandardIO
  • Stream

    • Introduction
    • TCStream
    • TIO
    • TStream
    • TStreamException
    • TStreamFactory
    • TStreamReadException
    • TStreamWrapper
    • TStreamWriteException

    StringBuilder

    • Introduction
    • TStringBuilder
    • TSplitBuffer
  • BRL.System
  • BRL.SystemDefault
  • BRL.TextStream
  • ThreadPool

    • Introduction
    • TRunnable
    • TThreadPoolExecutor

    Threads

    • Introduction
    • TThread
    • TThreadData
    • TMutex
    • TSemaphore
    • TCondVar

    Time

    • Introduction
    • ETimeUnit
    • TTimeoutException

    Timer

    • Introduction
    • TChrono
  • BRL.TimerDefault
  • Volumes

    • Introduction
    • TVolume
  • BRL.WAVLoader

Pub

  • Pub.FreeJoy
  • Pub.FreeProcess
  • Pub.Glad
  • Pub.Glew
  • Joystick

    • Introduction
    • TJoystickDriver
  • Pub.Lua
  • Pub.OpenAL
  • Pub.OpenGLES
  • StdC

    • Introduction
    • SDateTime
  • Pub.xmmintrin

Collections

    IntMap

    • Introduction
    • TIntMap

    ObjectList

    • Introduction
    • TObjectList
    • TObjectListEnumerator
    • TObjectListReverseEnumerator

    ObjectMap

    • Introduction
    • TObjectMap

    PtrMap

    • Introduction
    • TPtrMap

    StringMap

    • Introduction
    • TStringMap

Crypto

    Digest

    • Introduction
    • TMessageDigest
    • TDigestRegister

    Cipher

    • Introduction
    • TCipher
    • TCipherMode
    • Crypto.AESCipher
    • Crypto.AnubisCipher
    • Crypto.BlowfishCipher
    • Crypto.CamelliaCipher
    • Crypto.Cast5Cipher
    • Crypto.DESCipher
    • Crypto.IdeaCipher
    • Crypto.KasumiCipher
    • Crypto.KhazadCipher
    • Crypto.KSeedCipher
    • Crypto.NoekeonCipher
    • Crypto.SerpentCipher
    • Crypto.SkipjackCipher
    • Crypto.TwofishCipher
    • Crypto.XTeaCipher

    CBCMode

    • Introduction
    • TCBCCipherMode

    CFBMode

    • Introduction
    • TCFBCipherMode

    CTRMode

    • Introduction
    • TCTRCipherMode

    ECBMode

    • Introduction
    • TECBCipherMode

    F8Mode

    • Introduction
    • TF8CipherMode

    LRWMode

    • Introduction
    • TLRWCipherMode

    OFBMode

    • Introduction
    • TOFBCipherMode

    XTSMode

    • Introduction
    • TXTSCipherMode

    Blake2BDigest

    • Introduction
    • TBlake2B_512
    • TBlake2B_384
    • TBlake2B_256
    • TBlake2B_160

    CRC32

    • Introduction
    • TCRC32

    MD5Digest

    • Introduction
    • TMD5

    Ripemd320Digest

    • Introduction
    • TRipemd320

    Ripemd356Digest

    • Introduction
    • TRipemd256

    Ripemd160Digest

    • Introduction
    • TRipemd160

    Ripemd128Digest

    • Introduction
    • TRipemd128

    SHA1Digest

    • Introduction
    • TSHA1

    SHA256Digest

    • Introduction
    • TSHA256

    SHA512Digest

    • Introduction
    • TSHA512

    SHA3Digest

    • Introduction
    • TSHA3_512
    • TSHA3_384
    • TSHA3_256
    • TSHA3_224

    TigerDigest

    • Introduction
    • TTiger

    WhirlpoolDigest

    • Introduction
    • TWhirlpool

    Crypto

    • Introduction
    • TCryptoRandom
    • TCryptoSecretBox
    • TCryptoHash
    • TCryptoSign
    • TCryptoKeyExchange
    • TCryptoKey
    • TCryptoHashKey
    • TCryptoSecretBoxKey
    • TCryptoSignature
    • TCryptoExchangeKeyPair
    • TCryptoSessionKeyPair
    • TCryptoNPacket
    • TCryptoKK1Packet
    • TCryptoKK2Packet
    • TCryptoXX1Packet
    • TCryptoXX2Packet
    • TCryptoXX3Packet
    • TCryptoExchangeState
    • TCryptoPWHashMasterKey
    • TCryptoPWHashStoredKey
    • TCryptoPasswordHash

Math

    Matrix

    • Introduction
    • SMat2D
    • SMat2F
    • SMat2I
    • SMat3D
    • SMat3F
    • SMat3I
    • SMat4D
    • SMat4F
    • SMat4I

    Quaternion

    • Introduction
    • SQuatD
    • SQuatF
    • SQuatI

    Vector

    • Introduction
    • SVec2D
    • SVec2F
    • SVec2I
    • SVec3D
    • SVec3F
    • SVec3I
    • SVec4D
    • SVec4F
    • SVec4I

MaxGUI

  • MaxGUI.MaxGUI
  • MaxGUI.Drivers
  • MaxGUI.Localization
  • MaxGUI.ProxyGadgets
  • MaxGUI.CocoaMaxGUI
  • MaxGUI.Win32MaxGUIEx

Random

    Core

    • Introduction
    • TRandom
  • Random.PRVHASH
  • Random.Secure
  • SFMT

    • Introduction
    • TSFMTRandom
  • Random.Squares
  • Random.Xoshiro

SDL

    SDL

    • Introduction
    • TSDLStream

    SDLSystem

    • Introduction
    • TSDLMultiGesture

    SDLVideo

    • Introduction
    • TSDLDisplay
    • TSDLGLContext
    • TSDLWindow

    SDLRender

    • Introduction
    • TSDLRenderer
    • TSDLTexture

    SDLTimer

    • Introduction
    • TSDLTimer

    SDLHaptic

    • Introduction
    • TSDLHaptic
    • TSDLHapticCondition
    • TSDLHapticConstant
    • TSDLHapticCustom
    • TSDLHapticDirection
    • TSDLHapticEffect
    • TSDLHapticLeftRight
    • TSDLHapticPeriodic
    • TSDLHapticRamp

    SDLSensor

    • Introduction
    • TSDLSensor
  • SDL.SDLFreeAudio
  • SDL.GLSDLMax2D
  • SDL.GL2SDLMax2D
  • SDL.D3D9SDLMax2D
  • SDLVirtualJoystick

    • Introduction
    • TVirtualJoystick

Steam

    SteamSDK

    • Introduction
    • TSteamClient
    • TSteamUtils
    • TSteamUserStats
    • TSteamFriends
    • TSteamUGC
    • ISteamFriendsListener
    • ISteamUGCListener
    • ISteamUserStatsListener
    • ISteamUtilsListener
    • EItemPreviewType
    • EPersonaChange
    • EPersonaState
    • ERemoteStoragePublishedFileVisibility
    • EUGCMatchingUGCType
    • EUGCQuery
    • EUserRestriction
    • EUserUGCList
    • EWorkshopFileType

Text

    CP932Encoding

    • Text.CP932Encoding

    CSV

    • Introduction
    • TCsvParser
    • TCsvHeader
    • TCsvRow
    • TCsvOptions
    • SCsvColumn

    Encoding

    • Text.Encoding

    Format

    • Introduction
    • TFormatter

    Graphviz

    • Introduction
    • TGVGraphviz
    • TAGraph

    Ini

    • Introduction
    • TIni
    • TIniProperty
    • TIniSection

    JConv

    • Introduction
    • TJConv
    • TJConvBuilder
    • TJConvSerializer

    Json

    • Introduction
    • TJSON
    • TJSONObject
    • TJSONString
    • TJSONInteger
    • TJSONReal
    • TJSONBool
    • TJSONArray
    • TJSONNull
    • TJSONError
    • TJSONNumber

    Markdown

    • Introduction
    • TMarkdown
    • IMDRenderer

    Pikchr

    • Introduction
    • EPikChrFlags

    Regex

    • Introduction
    • TRegEx
    • TRegExMatch
    • TRegExOptions
    • TRegExException

    TOML

    • Introduction
    • ETomlNodeType
    • TToml
    • ITomlNode
    • STomlDate
    • STomlDateTime
    • STomlTime
    • TTomlArray
    • TTomlInteger
    • TTomlString
    • TTomlTable
    • TTomlBoolean

    Xml

    • Introduction
    • TxmlDoc
    • TxmlNode
    • TxmlAttribute
Edit

Random.Core

Introduction to Random Numbers

Random numbers are values generated in such a way that they appear unpredictable and evenly distributed within a given range. They are widely used in games, simulations, procedural generation, testing, and anywhere variation or chance is required.

On computers, random numbers are usually pseudo-random rather than truly random. This means they are produced by deterministic algorithms called random number generators (RNGs). Given the same starting state (called a seed), a pseudo-random generator will always produce the same sequence of values. This property is extremely useful for debugging, testing, and reproducing procedural content.

Random Number Generation in BlitzMax

BlitzMax provides a flexible random number system built around the Random.Core module. At its core is the abstract base class TRandom, which defines a common interface for all random number generators.

Concrete implementations of TRandom are provided by separate modules, such as BRL.Random, which contains the original BlitzMax random number generator. Other modules may provide alternative generators with different statistical properties or performance characteristics.

Global and Instance-Based Generators

BlitzMax supports two complementary ways of working with random numbers:

  1. Global random generator
  2. Explicit random generator instances

Global Random Generator

When you import a random module, it typically registers a generator and makes it available globally. If multiple random modules are imported, the last imported module becomes the default global generator.

The global generator is used by the standard random functions:

  • RndFloat()
  • RndDouble()
  • Rnd()
  • Rand()
  • SeedRnd()
  • RndSeed()

This allows most programs to use random numbers without needing to manage generator objects explicitly.

The active global generator can be queried or changed at runtime using:

  • GetRandomName() – returns the name of the current generator
  • GetRandomNames() – returns a list of all available generators
  • SetRandom(name) – selects a generator by name as the global default

If a generator name cannot be found, the currently active generator remains unchanged.

Generator Instances

In addition to the global generator, you can create independent instances of random number generators using CreateRandom().

This is useful when:

  • You need multiple independent random streams
  • You want deterministic behavior isolated from global state
  • You want to compare or switch between different RNG implementations

Instances can be created with or without an explicit seed, and optionally by specifying the generator name. If no name is given, the currently active global generator type is used.

Seeding and Reproducibility

Seeding controls the initial state of a random number generator.

  • SeedRnd(seed) sets the seed of the global generator
  • RndSeed() retrieves the current seed

Using the same seed will always produce the same sequence of random values, making it possible to reproduce results exactly. This is especially important for procedural generation, demos, and debugging.

Types

TypeDescription
TRandomRandom number generator

Functions

Function SetRandom(name:String)

Sets the current random number generator to name.

If no generator called name is found, the current random number generator remains active.


Function GetRandomName:String()

Gets the name of the current random number generator.

Returns

The name of the current random number generator, or Null if none is set.


Function GetRandomNames:String[]()

Gets the names of available random number generators.


Function CreateRandom:TRandom(name:String = Null)

Creates a new TRandom instance.


Function CreateRandom:TRandom(seed:Int, name:String = Null)

Creates a new TRandom instance with the given seed.


Function RndFloat:Float()

Generate random float

Returns

A random float in the range 0 (inclusive) to 1 (exclusive)


Function RndDouble:Double()

Generate random double

Returns

A random double in the range 0 (inclusive) to 1 (exclusive)


Function Rnd:Double(minValue:Double = 1, maxValue:Double = 0)

Generate random double

The optional parameters allow you to use Rnd in 3 ways:

FormatResult
`Rnd()`Random double in the range 0 (inclusive) to 1 (exclusive)
`Rnd(x)`Random double in the range 0 (inclusive) to n (exclusive)
`Rnd(x,y)`Random double in the range x (inclusive) to y (exclusive)

Returns

A random double in the range min (inclusive) to max (exclusive)


Function Rand:Int(minValue:Int, maxValue:Int = 1)

Generate random integer

The optional parameter allows you to use Rand in 2 ways:

FormatResult
`Rand(x)`Random integer in the range 1 to x (inclusive)
`Rand(x,y)`Random integer in the range x to y (inclusive)

Returns

A random integer in the range min (inclusive) to max (inclusive)


Function SeedRnd(seed:Int)

Set random number generator seed


Function RndSeed:Int()

Get random number generator seed

Used in conjunction with SeedRnd, RndSeed allows you to reproduce sequences of random numbers.

Returns

The current random number generator seed


← MaxGUI.Win32MaxGUIExTRandom →
  • Introduction to Random Numbers
  • Random Number Generation in BlitzMax
  • Global and Instance-Based Generators
    • Global Random Generator
    • Generator Instances
  • Seeding and Reproducibility
  • Types
  • Functions
    • Function SetRandom(name:String)
    • Function GetRandomName:String()
    • Function GetRandomNames:String[]()
    • Function CreateRandom:TRandom(name:String = Null)
    • Function CreateRandom:TRandom(seed:Int, name:String = Null)
    • Function RndFloat:Float()
    • Function RndDouble:Double()
    • Function Rnd:Double(minValue:Double = 1, maxValue:Double = 0)
    • Function Rand:Int(minValue:Int, maxValue:Int = 1)
    • Function SeedRnd(seed:Int)
    • Function RndSeed:Int()
BlitzMax
Docs
Getting StartedDownloadsAbout
Community
Resources
More
GitHubStarChat on Discord
Copyright © 2026 Bruce A Henderson