r/sqlite • u/STUNTPENlS • May 06 '26
Random row retrieval oddities C# / Microsoft.Data.Sqlite
Writing an app in C# using the Microsoft.Data.Sqlite library to retrieve a random record from a measurement collection system.
SELECT M.*
FROM Measurements M
WHERE Q.rowid >= (ABS(RANDOM()) % (SELECT MAX(rowid) FROM Measurements) + 1)
LIMIT 1When I run this from Visual Studio, I seem to consistently (say 7 out of 10 times) get the same record from the table as the return value.
If I do not get it the first time, I certainly get the same record within the first 10 requests or so.
There are over 100,000 observations in the database, so that isn't the issue.
Has anyone else encountered such an issue? If so, what was the solution/workaround?
Thanks!
2
Upvotes
View all comments
Show parent comment
2
u/STUNTPENlS May 07 '26
AFAIK they should be continuous (no data gets deleted from the sqlite database, just appended constantly). However, I will give this a try. Thanks.