For a project I had a specific requirement where I needed to show data in a random order. Instead of doing this code, I found an easy solution to do this using raw SQL.
The trick is to add an ORDER BY NewId() to your SQL statement. This is guaranteed to produce a different order every time.
Let’s show a quick example using the good old Northwind database:
When we execute this query, we'll see a different order everytime:
Next run: