What are common pitfalls when trying to display random images on a website using PHP?

One common pitfall when displaying random images on a website using PHP is not properly generating a random number to select an image from a list. To solve this, you can use the `rand()` function in PHP to generate a random number within the range of available images. Another pitfall is not properly handling file paths or image extensions, which can lead to broken image links. Ensure that the file paths are correct and that the images are in the correct format.

<?php
// List of image file paths
$images = [
    'image1.jpg',
    'image2.jpg',
    'image3.jpg',
];

// Generate a random number to select an image
$randomIndex = rand(0, count($images) - 1);

// Display the randomly selected image
echo '<img src="' . $images[$randomIndex] . '" alt="Random Image">';
?>