Last modified: 2011-09-09 13:40:26 UTC
There are times when it would be useful to be able to get a random item from a SMW query. For example, if you have a query that retrieves a random quote from a set of quotes. One way to do this would be to add a sort method called "random" or "shuffle" that would just scramble the result set before sending. This could be paired with a limit of 1 to get a single random result, or a handful. This is particularly needed when using a JSON query where there is too much data to return the entire result set to the client to then pick a random item.
This functionality already exists. * The sort parameter takes some property to sort on * The order parameter indicates how the sort should happen, and accepts "random" So a query with {{#ask:: ... | sort=Some property | order=random | limit=1 }} should work.