PostgreSQL/Math Functions/random
Версия от 13:45, 26 мая 2010; (обсуждение)
Get random number
postgres=#
postgres=# SELECT random();
random
-------------------
0.943210952423145
(1 row)
postgres=#
postgres=#
random(): Returns a pseudo-random value from 0.0 to 1.0
postgres=#
postgres=# --random(): Returns a pseudo-random value from 0.0 to 1.0
postgres=# SELECT random() AS natural_random,
postgres-# round(random() * 9) + 1 AS one_through_ten,
postgres-# trunc(random() * 99) + 1 AS one_through_one_hundred;
natural_random | one_through_ten | one_through_one_hundred
-------------------+-----------------+-------------------------
0.946445006386584 | 6 | 90
(1 row)
postgres=#