VB6Runtime / Library / Statements / randomize

VB6 Library Reference

Randomize Statement

Re-initializes the random-number generator with a new seed value.

Syntax

Randomize [number]

Arguments

Part Optional / Required Description
number Optional A Variant or any valid numeric expression that is used as the new seed value to initialize the random number generator.

Remarks

Implementation

This follows the VB6 runtime internals (rtRandomize and rtRandomizeValue in msvbvm60.dll), as preserved in .NET's VBMath.Randomize overloads, which are explicitly documented as equivalent to those two functions. Both forms take a value, XOR its low and high 16-bit halves, shift the result up 8 bits, and splice that into the middle 16 bits of the current seed while keeping the seed's top and bottom bytes. Because the low byte of the previous seed is preserved, re-randomizing with the same value does not repeat a sequence. - Omitted argument — the value is Single seconds since midnight (VB6 GetTimer), matching rtRandomize. - Numeric argument — the high 32 bits of the argument's Double representation are used, matching rtRandomizeValue. The spliced seed is stored as-is (it can exceed 24 bits); Rnd keeps the sequence 24-bit by masking when it advances.

Examples

' Initialize random number generator
Randomize
x = Int((100 * Rnd) + 1)
' Initialize with specific seed
Randomize 42
x = Rnd
' Use timer as seed
Randomize Timer

References

Microsoft VBA Language Reference - Randomize Statement

← Back to Statements | View all functions