w3resource

PostgreSQL RANDOM() function

RANDOM() function

The PostgreSQL random() function is used to return the random value between 0 and 1.

Uses of RANDOM() Function
  • Generating Random Values: To generate random numbers for use in various applications.

  • Simulations: Useful in simulations and modeling that require random input.

  • Data Sampling: To randomly sample data from a dataset.

  • Testing: Employed in testing scenarios where random data is needed to test algorithms and systems.

  • Game Development: To introduce randomness in game mechanics and algorithms.

Syntax:

random()

PostgreSQL Version: 9.3

Pictorial presentation of PostgreSQL RANDOM() function

pictorial presentation of PostgreSQL RANDOM() function

Example: PostgreSQL RANDOM() function

Code:

SELECT RANDOM() AS "Random Numbers";

Sample Output:

     Random Numbers
-------------------
 0.070854683406651
(1 row)

Previous: RADIANS function
Next: ROUND function



Become a Patron!

Follow us on Facebook and Twitter for latest update.

It will be nice if you may share this link in any developer community or anywhere else, from where other developers may find this content. Thanks.

https://w3resource.com/PostgreSQL/random-function.php