You are correct about the array and sometimes it will generate a random number outside the array limits. I corrected my post. All that was necessary was to change the assign to :
Code:
{assign var="rand" value="0"|mt_rand:"`$config.Modules.number_of_randomproducts-1`"}
Good catch.