How can storing available pages in an array improve the process of randomly loading pages in PHP?

When randomly loading pages in PHP, it can be inefficient to generate a random number each time to select a page. Storing the available pages in an array allows for quick access and eliminates the need to repeatedly generate random numbers. This can improve the efficiency of the process by reducing the time complexity of selecting a page.

// Store available pages in an array
$availablePages = ['page1.php', 'page2.php', 'page3.php', 'page4.php'];

// Get a random page from the array
$randomPage = $availablePages[array_rand($availablePages)];

// Load the randomly selected page
include($randomPage);