Snippets: updated sortrandom function