"""
Generate a random color in RGB format: rgb(R, G, B)
This program demonstrates how numbers and bits are used
to produce valid 8‑bit channel values.
"""
import random
def random_channel():
"""
Create a random 8‑bit integer (0–255).
random.random() gives a floating‑point number in [0, 1),
so multiplying by 256 (2**8) gives a range of 8 bits.
"""
# 8 bits → values from 0 to 255
return int(random.random() * 256)
def generate_random_rgb():
"""
Produce a random RGB color by combining the channels.
"""
r = random_channel() # Red channel (8 bits)
g = random_channel() # Green channel (8 bits)
b = random_channel() # Blue channel (8 bits)
# Construct the CSS-style RGB string
rgb = f"rgb({r}, {g}, {b})"
return r, g, b, rgb
# Run the program
r, g, b, rgb = generate_random_rgb()
print("Red (8 bits):", r)
print("Green (8 bits):", g)
print("Blue (8 bits):", b)
print("RGB color:", rgb)
"""
run:
Red (8 bits): 242
Green (8 bits): 120
Blue (8 bits): 74
RGB color: rgb(242, 120, 74)
"""