Here is one way to do it in JavaScript.
Code Select
<html>
<body>
<script type="text/javascript">
var intRed=Math.floor(Math.random()*256) // generates a random number between 0 and 255
var intGreen=Math.floor(Math.random()*256)
var intBlue=Math.floor(Math.random()*256)
var strHexRed = intRed.toString(16); // converts the number to hex
var strHexGreen = intGreen.toString(16);
var strHexBlue = intBlue.toString(16);
// make the value two characters wide so red, green, and blue each take two characters in the RGB value
if (strHexRed.length == 1) { strHexRed="0"+strHexRed; }
if (strHexGreen.length == 1) { strHexGreen="0"+strHexGreen; }
if (strHexBlue.length == 1) { strHexBlue="0"+strHexBlue; }
var strRGB=strHexRed+strHexGreen+strHexBlue; // joins the three string vales to make a RGB value
document.body.bgColor=strRGB;
document.write("The background page color is "+strRGB+"\n");
</script>
</body>
</html>