Random Favicon

From CodeCodex

Implementations[edit]

Perl[edit]

my @icons = <images/icons/*.ico>;

my $random_icon = $icons[ rand @icons ];

print qq{<link rel="shortcut icon" href="$random_icon">};

PHP[edit]

<highlightsyntax> <?php $dir = "images/icons/"; $files = array(); if ($handle = opendir($dir)) { while (false !== ($file = readdir($handle))) { $files[] = $file; } } $icon = $files[rand(2,count($files)-1)]; print '<link rel="shortcut icon" href="/images/icons/' . $icon . '" />'; ?> </pre>

Python[edit]

import glob, random

icons = glob.glob("images/icons/*.ico")

random_icon = random.choice(icons)

print '<link rel="shortcut icon" href="%s">' % random_icon