I also propose unifying the random number returned to be in the range
`[0.0, 1.0)` to make it more useful as the backend support differs:
||=**Backend** =||=**Function** =||=**Type** =||=**Range** =||=**Notes**
=||
|| PostgreSQL || [https://www.postgresql.org/docs/current/functions-
math.html#FUNCTIONS-MATH-RANDOM-TABLE RANDOM] || double precision ||
`[0.0, 1.0)` ||||
|| MySQL || [https://dev.mysql.com/doc/refman/8.0/en/mathematical-
functions.html#function_rand RAND] || double precision || `[0.0, 1.0)`
||||
|| MariaDB || [https://mariadb.com/kb/en/rand/ RAND] || double precision
|| `[0.0, 1.0)` ||||
|| Oracle || [https://docs.oracle.com/en/database/oracle/oracle-
database/19/arpls/DBMS_RANDOM.html#GUID-F401154C-
8A96-4634-93F9-BC4A8B52F9A7 DBMS_RANDOM.RANDOM] || integer || `[-2^31,
2^31)` || Currently used in Django, but Oracle have deprecated it. ||
|| Oracle || [https://docs.oracle.com/en/database/oracle/oracle-
database/19/arpls/DBMS_RANDOM.html#GUID-AAD9E936-D74F-440D-
9E16-24F3F0DE8D31 DBMS_RANDOM.VALUE] || number || `[0.0, 1.0)` ||||
|| SQLite || [https://sqlite.org/lang_corefunc.html#random RANDOM] ||
integer || `[-2^63, 2^63)` || We can use Python's `random.random()` for
`[0.0, 1.0)`||
This shouldn't adversely affect existing use cases of the expression as it
was undocumented and used to support `.order_by('?')`.
We should steer away from setting the random seed as it varies wildly
between backends.
We should also avoid any backend-specific arguments for the upper and
lower limits for the random number.
For anyone arriving here that wants to generate a random integer from a
random number in the range `[0.0, 1.0)` see the MySQL documentation for a
good example.
--
Ticket URL: <https://code.djangoproject.com/ticket/32060>
Django <https://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.
* has_patch: 0 => 1
Comment:
[https://github.com/django/django/pull/13473 PR]
--
Ticket URL: <https://code.djangoproject.com/ticket/32060#comment:1>
* type: Cleanup/optimization => New feature
* stage: Unreviewed => Accepted
--
Ticket URL: <https://code.djangoproject.com/ticket/32060#comment:2>
* stage: Accepted => Ready for checkin
--
Ticket URL: <https://code.djangoproject.com/ticket/32060#comment:3>
* status: assigned => closed
* resolution: => fixed
Comment:
In [changeset:"06c5d3fafc6aeb96387148726713b611aeba7fa1" 06c5d3f]:
{{{
#!CommitTicketReference repository=""
revision="06c5d3fafc6aeb96387148726713b611aeba7fa1"
Fixed #32060 -- Added Random database function.
}}}
--
Ticket URL: <https://code.djangoproject.com/ticket/32060#comment:4>