Skip to content

Instantly share code, notes, and snippets.

@georgepsarakis
Created July 8, 2013 18:45
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save georgepsarakis/5951381 to your computer and use it in GitHub Desktop.
Save georgepsarakis/5951381 to your computer and use it in GitHub Desktop.
Mathematical & Random Numbers MySQL Functions
-- Random integer between 2 signed integers
DROP FUNCTION IF EXISTS RANDINT;
DELIMITER //
CREATE FUNCTION RANDINT(a INT, b INT) RETURNS INT
BEGIN
RETURN FLOOR( ABS(a-b) * RAND() ) + IF(a > b, b, a);
END//
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment