3 ms·
Been working with sqlite and Typescript, needing random rows sampled reproducibly with a seed. Found this handy little trick [0]. Not the cleanest, but it works
by peterm4 2y ago
Been working with sqlite and Typescript, needing random rows sampled reproducibly with a seed. Found this handy little trick [0]. Not the cleanest, but it works!
`SELECT * FROM sales ORDER BY substr(${seedValue} * sales.id, length(sales.id) + 2) LIMIT 10;`
[0] https://stackoverflow.com/questions/24256258/order-by-random-with-seed-in-sqlite https://stackoverflow.com/questions/24256258/order-by-random...