totn Access Functions

MS Access: Randomize Function

This MSAccess tutorial explains how to use the Access Randomize function with syntax and examples.

Description

The Microsoft Access Randomize function allows you to change the seed value used by the random number generator for the Rnd function.

Syntax

The syntax for the Randomize function in MS Access is:

Randomize ( [ seed ] )

Parameters or Arguments

seed
Optional numeric value. It is the seed that will be used by the RND function to generate a random number. If no seed value is provided, Access will use the system timer as the seed value for the Rnd function.

Applies To

The Randomize function can be used in the following versions of Microsoft Access:

  • Access 2019, Access 2016, Access 2013, Access 2010, Access 2007, Access 2003, Access XP, Access 2000

Example in VBA Code

The Randomize function can only be used in VBA code in Microsoft Access.

For example:

'Example provided by techonthenet.com

Dim LRandomNumber As Integer

Randomize
LRandomNumber = Int ((300 - 200 + 1) * Rnd + 200)

In this example, the variable called LRandomNumber would now contain a random number between 200 and 300. The Randomize function would ensure that the number generated is truly random by initializing the random number generator with a seed value that is equivalent to the system timer.

Warning: If you don't call the Randomize function before calling the Rnd function, the Rnd function may return the same random number value each time. And therefore, you may not get a truly random number.