Not tested well but you can try this.
add_action( 'template_redirect', 'my_homepage_redirect' );
function my_homepage_redirect() {
if ( is_home() || is_front_page() ){
$page = get_posts( [
'post_type' => 'page',
'posts_per_page' => 1,
'orderby' => 'rand',
'fields' => 'ids'
] );
if ( empty( $page ) ){
return;
}
// update the front page id option according to the page id
update_option( 'page_on_front', $page[0]);
}
}