Created
February 17, 2016 19:57
-
-
Save swayson/84fc86da20db89b56eac to your computer and use it in GitHub Desktop.
Efficient way to do random sampling in SQLite.
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
SELECT * FROM table | |
WHERE _ROWID_ >= (abs(random()) % (SELECT max(_ROWID_) FROM table)) | |
LIMIT 1 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Wow, this is an old gist I forgot about 😅
Looks great and thanks for the detailed description on the implementation. Think this is great learning material and will help folks 👍