Beginner

260. RAND Function

Learn how SQL databases can generate pseudo-random numeric values.

📘 Lesson 260 of 728 ⏱ 8 min 🎯 Intermediate

A RAND function generates a pseudo-random numeric value, commonly between zero and one, depending on the database system and function implementation.

Random values can be useful for testing, sampling, demonstrations, and generating temporary analytical data.

Generate a random value for testing purposes.

SQL
SELECT
    RAND() AS RandomValue;

Random functions can support test-data generation, sampling experiments, simulations, and development activities.

  • RAND generates a pseudo-random value.
  • The exact range depends on the database.
  • It is useful for testing and sampling.
  • Random values are not normally suitable for security purposes.
  • Database implementations differ.
What is RAND used for?

RAND is used to generate pseudo-random numeric values.

Can RAND be used for security-sensitive random values?

Generally no. Database random functions are not intended to replace cryptographically secure random generators.

Have you finished this lesson?

Introduction to SQL – All Lessons