Home  >  Article  >  Backend Development  >  php generate random colors

php generate random colors

WBOY
WBOYOriginal
2016-07-25 08:45:27730browse

A piece of PHP code to generate random colors, such as: FF00FF

  1. function random_color(){
  2. mt_srand((double)microtime()*1000000);
  3. $c = '';
  4. while(strlen($c) <6){
  5. $c .= sprintf("%02X", mt_rand(0, 255));
  6. }
  7. return $c;
  8. }
  9. //Usage example:
  10. random_color() => returns something like: '7C42BA', '5F3964'
Copy code

php


Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn