Created
March 11, 2023 16:51
-
-
Save sfaut/7e13efb44b1a4eca984764027200dd82 to your computer and use it in GitHub Desktop.
Get a random integer between start and stop excluded
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
-- Get a random integer between start and stop excluded | |
-- Author : sfaut <https://github.com/sfaut> | |
-- Publication date : 2023-03-11 | |
-- Tested with MySQL 8.0.32 (@@sql_mode='ANSI,TRADITIONAL') | |
CREATE FUNCTION RANDOM_INTEGER(start INT, stop INT) | |
RETURNS INT | |
NOT DETERMINISTIC | |
NO SQL | |
COMMENT 'Get a random integer between start and stop excluded' | |
RETURN FLOOR(start + RAND() * (stop - start)); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment