Home > Backend Development > PHP Tutorial > php generate random colors

php generate random colors

WBOY
Release: 2016-07-25 08:45:27
Original
745 people have browsed it

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


Related labels:
source:php.cn
Statement of this Website
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template