Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Random function #4661

Open
vanillajonathan opened this issue Jun 24, 2024 · 2 comments
Open

Random function #4661

vanillajonathan opened this issue Jun 24, 2024 · 2 comments

Comments

@vanillajonathan
Copy link
Collaborator

What's up?

PRQL does not yet have any random function(s). SQL have the RAND function which can be used awkwardly used using s-strings.

It would be nice if PRQL has a random function, it could work like randint in Python, i.e. take in a low and high parameter in order to specify a range. The SQL RAND function does not have this feature it can takes a seed as parameter.

derive { random_value = (random low:100 high:1000) }
SELECT FLOOR(100 + RAND() * (1000 - 100 + 1)) AS random_value;

It could even generate a random letter:

derive { random_letter = (random low:A high:Z) }
SELECT CHAR(FLOOR(RAND() * (ASCII('A') - ASCII('Z')))) AS random_letter;
@max-sixty
Copy link
Member

Yes, would be happy to add this. Probably start with math.randint?

@vanillajonathan if you want to add, search for math.abs as an example.

@aljazerzen
Copy link
Member

aljazerzen commented Jul 2, 2024

Note that random is an impure function and suffers from the problem described in #1111

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants