display random posts on index.php instead of latest

Place the following code in your theme functions.php file.

function one_random_post_on_home_page( $query )
{
    if ( ! ( $query->is_home() && $query->is_main_query() ) )
        return;

    $query->set( 'orderby ', 'rand' );
    $query->set( 'posts_per_page', 1 );
}

add_action( 'pre_get_posts', 'one_random_post_on_home_page' );

I’m assuming when you say index.php you mean your blogs home page. The index.php file in your theme can be used for many other areas of your website so making any alterations in that file might have undesired effects else where.

tech