BeauLebens.com

An aggregation of Beau on the internet

Menu

Skip to content
  • Blog
  • Archive
    • Posts
      • Tweets
    • Images
      • Flickr
      • Instagram
    • Links
      • Delicious
      • Instapaper
    • Places
      • Check-ins
      • Trips
  • Explore
  • Projects

#eric scheid

Better Random Hex

  • #code
  • #eric scheid
  • #hex
  • #php
  • #random hex
  • #randomizer

Eric Scheid (founder of the excellent IAWiki) shot me a line with a more efficient and much sleeker version of my random hex code straight after I posted it, so here it is!

function random_hex() {
	$color = '';
	for ($c = 0; $c < 6; $c++) {
		$i = rand(0, 15);
		$color .= substr("0123456789ABCDEF", $i, 1)
	}
	$color = '#' . $color;
	return $color;
}

Thanks Eric!

9:54 pm, April 14, 2005

Post navigation

People

  • Erika Schenck (1,816)
  • Helen Hou-Sandi (194)
  • Automattic (177)
  • Scott Taylor (132)
  • Kelly Hoffman (131)

Categories

  • Uncategorized (28,819)
  • Personal (9,315)
  • Posts (304)
  • Techn(ical|ology) (192)
  • Projects (77)

Tags

  • read (3,919)
  • wordpress (624)
  • sanfrancisco (421)
  • automattic (394)
  • photo (392)

Year

  • 2025 (201)
  • 2024 (1,014)
  • 2023 (953)
  • 2022 (819)
  • 2021 (906)
Powered by Homeroom for WordPress.
 

Loading Comments...