Skip to content

Instantly share code, notes, and snippets.

@PHLAK
Created July 6, 2011 16:26
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save PHLAK/1067666 to your computer and use it in GitHub Desktop.
Save PHLAK/1067666 to your computer and use it in GitHub Desktop.
Generates random characters with random background and foreground colors.
<?php
function randColor() {
$randDec = rand(0, 16777215);
$randHex = dechex($randDec);
$color = '#' . $randHex;
return $color;
}
function randChar() {
// Define possible characters
$chars = 'abcdefghijklmnopqrstuvwxyz0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ!@#$%^&*()-_=+[];,./{}:<>?\|~';
// Pick a random char
$x = rand(0, strlen($chars)-1);
$char = $chars{$x};
return $char;
}
?>
<?php $i = 0; while ($i < 2500): ?>
<span style="background-color: <?= randColor(); ?>; color: <?= randColor(); ?>; display: inline-block; float: left; padding: 2px 0; text-align: center; width: 12px;">
<?= randChar(); ?>
</span>
<?php $i++; endwhile; ?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment