note 40923 deleted from function.rand by nlopess
| From: | nlopess@php.net | Date: | Tue, 23 Mar 2004 17:15:14 +0000 |
| Subject: | note 40923 deleted from function.rand by nlopess | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-67063@lists.php.net to get a copy of this message | ||
Note Submitter: cfranklin@nomadcf.com
----
Heres how to create random yet web-safe colors in hex using rand().
$Color = '#'.substr(md5(rand()),0,6);
I'll explain from the insdie out.
rand() = creates a random number.
md5 = Turns that random number in to a 32 bit long hex
number.
substr(,0,6) = takes the 1st 6 hex chars from the MD5 string.