Last active
September 25, 2019 00:10
-
-
Save danielleevandenbosch/e8dd49d1b0984db8ae1754cd636ad86f to your computer and use it in GitHub Desktop.
Made for my stats class (PostgreSQL)
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
CREATE SCHEMA it; | |
CREATE OR REPLACE FUNCTION it.random_between(low INT ,high INT) | |
RETURNS INT AS | |
$$ | |
BEGIN | |
RETURN floor(random()* (high-low + 1) + low); | |
END; | |
$$ language 'plpgsql' STRICT; | |
CREATE FUNCTION it.dice_roles (number_of_roles INT default 1) RETURNS TABLE (a int, b int, roll int) LANGUAGE sql AS | |
$$ | |
/* | |
================================================== | |
Author: dvandenbosch | |
Created At: 9/24/2019 | |
Where Used: | |
================================================== | |
*/ | |
SELECT a,b,roll | |
FROM ( | |
SELECT a + b AS roll, a,b | |
FROM (SELECT (generate_series(1, number_of_roles) * 0 + it.random_between(1, 6)) AS a, | |
(generate_series(1, number_of_roles) * 0 + it.random_between(1, 6)) AS b) AS foo | |
) AS bar | |
ORDER BY roll | |
; | |
$$; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment