```sql select your_columns from your_table ORDER B...
# sql
k
Copy code
sql
select your_columns from your_table ORDER BY random()
b
Here's how I do it, and this will work if you use UUIDs as your IDs:
Copy code
const { data, error } = await this.supabase
    .from('questions')
    .select('*')
    .order('id', { ascending: true })
    .filter('id', 'gte', this.uuid() /* create a random uuid */)
    .limit(1);
My function to create a random UUID on the client (if you don't already have one):
Copy code
public uuid() {
    return "xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx".replace(/[xy]/g, (char) => {
      let random = Math.random() * 16 | 0;
      let value = char === "x" ? random : (random % 4 + 8);
      return value.toString(16);     
    });
  }
k
^^ good solution too
b
I use this because in theory it would be more performant than using
ORDER BY random()
with very large recordsets, since it's using an existing index.
b
Thank you very much🙏