Generating a random number without duplicates on blog comment A section of my site is a blog where I allow comments. Each comment has a thumbnail associated with it. If the commenter is a user, then their profile photo is used. If they are anonymous I have a pre-determined photo in place. I want to be able to randomly generate a thumbnail for these anonymous users, but also have no duplicates. 

I asked this question here and now have a random thumbnail being generated, but the problem is that there are still duplicates. And it looks like because the comment.tpl.php file is being read on each comment that the random numbers are not being remembered. 

How can Drupal remember the number so that it doesn't use it again?

My Code:

$numbers = range(0, 19);
shuffle($numbers);

print "&lt;div id='commenter-picture'&gt;";
print "&lt;img src='member_default_" . array_pop($numbers) . ".png' /&gt;";
print "&lt;/div&gt;";
Haven't tested this, but I think this should work. Remove your first two lines of code and place the following in your theme's template.php file (replace MYTHEME with the machine name of your theme):

function MYTHEME_preprocess_comment(&amp;$vars){
    $max = 19;
    $numbers =  $_SESSION['MYTHEME_comment_numbers'] ?: range(0, $max);
    shuffle($numbers);
    $vars['number'] = array_pop($numbers);
    $_SESSION['MYTHEME_comment_numbers'] = count($numbers) ? $numbers : range(0, $max);
}

This makes available a $number variable inside your comment.tpl.php file.

Then, replace your last three lines inside comment.tpl.php with:

print "&lt;div id='commenter-picture'&gt;";
print "&lt;img src='member_default_" . $number . ".png' /&gt;";
print "&lt;/div&gt;";


This will remove already used numbers from your $numbers array until there's none left, and then reset to use the full array again.