©SQL :: Manager
HomeProgram InformationTechnical detailsFree downloadDonate for a cup of coffee
myway SQL Manager for MySQL and MariaDB, Download on Uptodown
SQL functionMySQLMariaDB

The RAND SQL Function in MySQL and MariaDB - Random value calculation

RANDSyntax:RAND([Number])
Return value:FLOAT
Function type:Numeric function
Function Description

The RAND() function returns a random floating point value with double precision from 0 to 1.

If "Number" is specified, it is used as the seed that produces a repeatable sequence of values ​​for multi-row queries.

If the value of "Number" is NULL, the same value is returned as with RAND(0).

SQL Examples for the RAND function

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13

select rand();
select rand();
select rand(4);
select rand(4);
select rand(0);
select rand(null);

select id, rand() from menu limit 3;
select id, rand() from menu limit 3;
select id, rand(4) from menu limit 3;
select id, rand(4) from menu limit 3;

rand()
double(23)
0.6991170977234068
rand()
double(23)
0.7097095229753382
rand(4)
double(23)
0.15595286540310166
rand(4)
double(23)
0.15595286540310166
rand(0)
double(23)
0.15522042769493574
rand(null)
double(23)
0.15522042769493574
id
rand()
menu
tinyint(4)

double(23)
10.4511963524401154
20.12685322400820742
30.2806770934543359
id
rand()
menu
tinyint(4)

double(23)
10.022825825980702253
20.27209788027414855
30.292011954162281
id
rand(4)
menu
tinyint(4)

double(23)
10.15595286540310166
20.6238114970026645
30.6511989195376624
id
rand(4)
menu
tinyint(4)

double(23)
10.15595286540310166
20.6238114970026645
30.6511989195376624
The examples were created with the MyWAY SQL manager: Download

How to use the RAND() function in MySQL and MariaDB databases

The RAND() function in MySQL and MariaDB is commonly used when there is a need to generate random values ​​for testing, simulation, random sampling, or other scenarios where randomness is required in SQL queries. To generate random numbers within a certain range, the RAND() function can be combined with mathematical operations.
QUARTERQUOTERADIANSRANDRANDOM_BYTESREGEXPREGEXP_INSTR

Further MySQL und MariaDB SQL Numeric functions

BIT_COUNTBIT_COUNT(Integer)
More about BIT_COUNT Function

CEILCEIL(Number)
More about CEIL Function

CEILINGCEILING(Number)
More about CEILING Function

CRC32CRC32(String)
More about CRC32 Function

CRC32CCRC32C([Parameter], String)

FLOORFLOOR(Number)
More about FLOOR Function

SIGNSIGN(Number)
More about SIGN Function

ABSABS(Number)
More about ABS Function

ACOSACOS(Number)
More about ACOS Function

ASINASIN(Number)
More about ASIN Function

ATANATAN(Number [, Number2])
More about ATAN Function

ATAN2ATAN2(Number [, Number2])
More about ATAN2 Function

COSCOS(Number)
More about COS Function

COTCOT(Number)
More about COT Function

DEGREESDEGREES(Number)
More about DEGREES Function

EXPEXP(Number)
More about EXP Function

LNLN(Number)
More about LN Function

LOGLOG([Base], Number)
More about LOG Function

LOG10LOG10(Number)
More about LOG10 Function

LOG2LOG2(Number)
More about LOG2 Function

MODMOD(Number, Divider)
More about MOD Function

POWPOW(Number, Exponent)
More about POW Function

POWERPOWER(Number, Exponent)
More about POWER Function

PIPI()
More about PI Function

RADIANSRADIANS(Number)
More about RADIANS Function

ROUNDROUND(Number [, Decimals])
More about ROUND Function

SINSIN(Number)
More about SIN Function

SQRTSQRT(Number)
More about SQRT Function

TANTAN(Number)
More about TAN Function

TRUNCATETRUNCATE(Number, Decimals)
More about TRUNCATE Function

Numeric functionsString functionsRegular ExpressionsDate and Time functions
Comparison functionsEncryption & CompressionConversion functionsNULL functions
Aggregate functionsWindow functionsJSON functionsGeometric functions
Sequence functionsInformation functionsDynamic ColumnsMiscellaneous functions
More information about the RAND SQL function: mysql.com and mariadb.com and w3schools.com
Updated: 2023-09-24ImprintContactTerms & conditionsPrivacy & CookiesUpdatesSitemapFacebookLinkedinTwitterStatistics©2020-2024 Heino Cunze-Fischer