CFLib.org – Common Function Library Project

RandomColor()

Last updated May 13, 2003

author

Nathan Strutz

Version: 2 | Requires: CF5 | Library: UtilityLib

Description:
Simply place RandomColor() anywhere you want a truly random HTML color. Fun for the whole family!

Return Values:
Returns a string.

Example:

<cfoutput>
<table border=1 cellspacing=0>
  <tr>
<cfloop from=1 to=10 index="z">
	<td bgcolor="#RandomColor()#">&nbsp;</td>
</cfloop>
  </tr>
  <tr>
<cfloop from=1 to=10 index="z">
	<td bgcolor="#RandomColor()#">&nbsp;</td>
</cfloop>
  </tr>
</table>
</cfoutput>

Parameters:

No arguments.

Full UDF Source:

/**
 * Returns a completely random color. Beautiful, isn't it?
 * Version 2 by Raymond Camden
 * 
 * @return Returns a string. 
 * @author Nathan Strutz (nathans@dnsfirm.com) 
 * @version 2, May 13, 2003 
 */
function randomColor() {
	var redColor = formatBaseN(randRange(0,255),16);
	var greenColor = formatBaseN(randRange(0,255),16);
	var blueColor = formatBaseN(randRange(0,255),16);
	
	if(len(redColor) is 1) redColor = "0" & redColor;
	if(len(greenColor) is 1) greenColor = "0" & greenColor;
	if(len(blueColor) is 1) blueColor = "0" & blueColor;

	return "##" & redColor & greenColor & blueColor;
}
blog comments powered by Disqus

Search CFLib.org


Latest Additions

Kevin Cotton added
date2ExcelDate
May 5, 2016

Raymond Camden added
CapFirst
April 25, 2016

Chris Wigginton added
loremIpsum
January 18, 2016

Gary Stanton added
calculateArrival...
November 19, 2015

Sebastiaan Naafs - van Dijk added
getDaysInQuarter
November 13, 2015

Created by Raymond Camden / Design by Justin Johnson