Golang Tutorials - Learn Go Programming with Easy Step-by-Step Guides

Explore comprehensive Golang tutorials for beginners and advanced programmers. Learn Go programming with easy-to-follow, step-by-step guides, examples, and practical tips to master Go language quickly.

Rand Function In Sql in SQL

Rand Function In Sql in SQL

RAND Function in SQL

The RAND() function generates a random floating-point number between 0 (inclusive) and 1 (exclusive).


Syntax:

RAND()

You can optionally provide a seed to generate repeatable sequences:

RAND(seed)
  • seed — an integer value to initialize the random number generator.


Example:

Generate a random number between 0 and 1:

SELECT RAND() AS random_value;

Example with Seed:

SELECT RAND(123) AS random_value;

Calling RAND(123) multiple times will generate the same sequence of numbers.


Notes:

  • Supported in MySQL, SQL Server, and others.

  • To get a random number within a range, multiply and add accordingly. For example, random integer between 1 and 10 in MySQL:

SELECT FLOOR(1 + RAND() * 10) AS random_int;

Want examples on how to use RAND() for selecting random rows or other use cases?

Disclaimer for AI-Generated Content:
The content provided in these tutorials is generated using artificial intelligence and is intended for educational purposes only.
html
docker
php
kubernetes
golang
mysql
postgresql
mariaDB
sql