Using Zen Cart 1.5.6c

I get this error if there is no image for an item.. I have 20k items and a ton of categories.. I do try and correct the problem, but I'd rather it just put "NoImage.jpg" instead of throwing an error.

Any help would be appreciated.

This is error

PHP Warning: array_rand() expects parameter 1 to be array .... httpdocs/includes/functions/extra_functions/functions_auto_category_images.php on line 13

This is line 13:

$image = auto_category_images( $sub_categories[array_rand( $sub_categories, 1 )] );

PHP Code:
<?php

    
function auto_category_images$catID ) {
        global 
$db;

        if ( 
$catID ) {

            
$cat_has_products $db->Execute("SELECT p.products_image FROM " TABLE_PRODUCTS " p, " TABLE_PRODUCTS_TO_CATEGORIES " p2c WHERE p.products_id = p2c.products_id AND p2c.categories_id = " $catID " ORDER BY RAND() LIMIT 1");
            if(
$cat_has_products->RecordCount() > 0){
                
$image $cat_has_products->fields['products_image'];
            } else {
                
zen_get_subcategories$sub_categories$catID );
                
$image auto_category_images$sub_categories[array_rand$sub_categories)] ); 
              }
        } else {
            
// This category contains no products!
            
$image 'pixel_trans.gif';
        }

        return 
$image;
    }

?>