<?xml version="1.0" encoding="UTF-8"?>
<commit>
  <added type="array"/>
  <modified type="array">
    <modified>
      <diff>@@ -11,20 +11,20 @@ build_monster($_REQUEST['seed'], $_REQUEST['size']);
  * GDlib is required!
  */
 function build_monster($seed='',$size='') {
-    // init random seed
-    if($seed) srand( hexdec(substr(md5($seed),0,6)) );
+    // create 16 byte hash from seed
+    $hash = md5($seed);
 
-    // throw the dice for body parts
+    // calculate part values from seed
     $parts = array(
-        'legs' =&gt; rand(1,5),
-        'hair' =&gt; rand(1,5),
-        'arms' =&gt; rand(1,5),
-        'body' =&gt; rand(1,15),
-        'eyes' =&gt; rand(1,15),
-        'mouth'=&gt; rand(1,10)
+        'legs' =&gt; _get_monster_part(substr($hash, 0, 2), 1, 5),
+        'hair' =&gt; _get_monster_part(substr($hash, 2, 2), 1, 5),
+        'arms' =&gt; _get_monster_part(substr($hash, 4, 2), 1, 5),
+        'body' =&gt; _get_monster_part(substr($hash, 6, 2), 1, 15),
+        'eyes' =&gt; _get_monster_part(substr($hash, 8, 2), 1, 15),
+        'mouth'=&gt; _get_monster_part(substr($hash, 10, 2), 1, 10),
     );
 
-    // create backgound
+    // create background
     $monster = @imagecreatetruecolor(120, 120)
         or die(&quot;GD image create failed&quot;);
     $white   = imagecolorallocate($monster, 255, 255, 255);
@@ -42,7 +42,10 @@ function build_monster($seed='',$size='') {
 
         // color the body
         if($part == 'body') {
-            $color = imagecolorallocate($monster, rand(20,235), rand(20,235), rand(20,235));
+            $r = _get_monster_part(substr($hash, 0, 4), 20, 235);
+            $g = _get_monster_part(substr($hash, 4, 4), 20, 235);
+            $b = _get_monster_part(substr($hash, 8, 4), 20, 235);
+            $color = imagecolorallocate($monster, $r, $g, $b);
             imagefill($monster,60,60,$color);
         }
     }
@@ -64,5 +67,10 @@ function build_monster($seed='',$size='') {
         imagepng($monster);
         imagedestroy($monster);
     }
+    
+}
+
+function _get_monster_part($seed, $lower = 0, $upper = 255) {
+    return hexdec($seed) % ($upper - $lower) + $lower;
 }
 // vim:ts=4:sw=4:et:enc=utf-8:</diff>
      <filename>monsterid.php</filename>
    </modified>
  </modified>
  <removed type="array"/>
  <parents type="array">
    <parent>
      <id>2ea20d43dea51a958e66f9526c53a73491d777d6</id>
    </parent>
  </parents>
  <author>
    <name>Gina Haeussge</name>
    <email>osd@foosel.net</email>
  </author>
  <url>http://github.com/dokufreaks/plugin-avatar/commit/2e0c1c6e18d9ca12a36c69bdf0ae58bd71270096</url>
  <id>2e0c1c6e18d9ca12a36c69bdf0ae58bd71270096</id>
  <committed-date>2009-01-11T04:36:46-08:00</committed-date>
  <authored-date>2009-01-11T04:36:46-08:00</authored-date>
  <message>Switch from srand to hash-based generation of monsterid

darcs-hash:20090111123646-2b4f5-7bf013d2360b86c60af608039fada3cf1f8a0d6e.gz</message>
  <tree>05d954846e608a4c0d906818c443f916ac49f7ad</tree>
  <committer>
    <name>Gina Haeussge</name>
    <email>osd@foosel.net</email>
  </committer>
</commit>
