CFLib.org – Common Function Library Project

RandomColor()

Last updated May 13, 2003

Version: 2 | Requires: ColdFusion 5 | Library: UtilityLib

 
Rated 1 time(s). Average Rating: 5.0

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

Return Values:
Returns a string.

Example:

view plain print about
<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:

view plain print about
<cfscript>
/**
 * 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;
}
</cfscript>
blog comments powered by Disqus

Search CFLib.org


Latest Additions

Tayo Akinmade Tayo Akinmade added
arrayTrim
3 day(s) ago

Will Belden Will Belden added
longTime
9 day(s) ago

James Sleeman James Sleeman added
quickSort
19 day(s) ago

Ben Forta Ben Forta added
GetHostAddress
22 day(s) ago

Top Rated

Darwan Leonardo Sitepu EksporSQLData
Rated 5.0, 16 time(s)

Darwan Leonardo Sitepu backupDatabase
Rated 5.0, 13 time(s)

Barney Boisvert indentXml
Rated 5.0, 10 time(s)

Kevin Pepperman generateSsccAsn
Rated 5.0, 4 time(s)

Created by Raymond Camden / Design by Justin Johnson