PHP
<?php
function tu_rand_posts( $query ) {
if ( $query->is_main_query() && ! is_admin() ) {
$query->set( 'orderby', 'rand' );
}
}
add_action( 'pre_get_posts', 'tu_rand_posts' );