﻿id	summary	reporter	owner	description	type	status	component	version	severity	resolution	keywords	cc	stage	has_patch	needs_docs	needs_tests	needs_better_patch	easy	ui_ux
32060	Expose Random() as a function instead of an expression.	Nick Pope	Nick Pope	"This follows on from #31839 where all other proposals were rejected, but exposing `Random()` as a function was [https://code.djangoproject.com/ticket/31839#comment:6 accepted].

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."	New feature	closed	Database layer (models, ORM)	dev	Normal	fixed	random, function.		Ready for checkin	1	0	0	0	0	0
