I have six digit random number like 1424517,1420422 and so on. Is there any way to use this number to make html color code and i used it as background:#1424517 to make some background color.
-
Do you want to ask how to change color randomly every time you load a page? – lulalala Nov 28 '13 at 06:29
-
4Looks like your 6 digit numbers have 7 digits – vals Nov 28 '13 at 06:31
-
You can put a “#” before a six-digit sequence to produce a color code. So what is the problem? – Jukka K. Korpela Nov 28 '13 at 08:49
-
You can calculate a hash from that value and use that as Color. You can build a really big Color Array und use your value as an index into the table. You can do whatever you want. – Werner Henze Nov 28 '13 at 09:44
3 Answers
CSS color codes are 8bit-RGB by default. I assume, you have a single 24-bit number. You can simply convert it to a CSS color code, by formatting it as hexadecimal.
If you have 3 8-bit numbers, you can construct a number like this:
color = (val1 % 256, val2 % 256, val3 % 256);
Where "%" is the modulo operator.
I am not sure what exactly you are asking, but I'm assuming that you want to randomly select a color for a webpage. Colors are done in RGB Hexadecimal typically, ranging from #000000 (black) to #FFFFFF (white). #0000FF would be pure blue, #00FF00 would be pure green, and #FF0000 would be pure red. By changing the values you will have different colors. You could always generate a random number between 0 and 16777215 (256^3-1) and convert that to hex.

- 87
- 6
html color codes can be in 3 formats:
- hex value(#123abc)
- rgb which ranges from 0-255, rgb(100,100,100), and
- direct name of the colors(eg: red, green blue)

- 98
- 4