query_posts()
allows for an argument called orderby
, there you can provide how you want your posts sorted. So a solution could look like this
$args['orderby'] = 'rand';
query_posts($args);
For a full list and explanation of the query arguments, check WordPress Developer Resources on WP_Query