Let's analyze your code:
WHEN hour("time") = X THEN color_rgb(rand(0, 255), rand(0, 255), rand(0, 255))
When the hour of the current time is X what this does is it creates a color with random RGB values. The Red value is random, the Green value is random, and the Blue value is random. Every time it executes each of the Red, Green and Blue values is random, and will be different each time it's called, even if called with the exact same time, so your code can't possibly work as intended. What you need to do is to ensure that you get the same random color for a given hour.
If getting a random color for each of the 24 hours, with different days having the same random color for the same hours, and if rand works with a seed as shown above, and if hour("time") returns an integer, (a lot of if's, but I'm not familiar with this environment) then you could do something like the following:
color = color_rgb(
rand(0, 255, hour("time")*10),
rand(0, 255, hour("time")*20),
rand(0, 255, hour("time")*30)
)
Note that you don't have to use a case statement at all, it's 1 line of code! There is a possible subtle race condition here if hour("time") is using the time of the call, as opposed to a fixed time calculated before getting into this code, where getting the hour multiple times could end up with the first call being in hour X and the second or third call being in hour X+1, creating a totally new color that doesn't match the colors for either hour X or hour X+1... To guarantee the random values are the same efficient you could get hour("time") once and use it repeatedly, rather than getting it each time (again, assuming that hour("time") gets the current time)...
This uses the hour value (multiplied by a different multiplier for each of R, G and B else the R, G and B values will be identical and you'll get shades of gray) as the seed for the random numbers. So, when the code is executed and the hour is X the same R, G and B seeds will be used and will generate the same random numbers for each of R, G and B values for that time.
If you want the colors for each hour to be different every day you could do something like this (again, assuming day("time") returns an integer):
color = color_rgb(
rand(0, 255, hour("time")*day("time")*10),
rand(0, 255, hour("time")*day("time")*20),
rand(0, 255, hour("time")*day("time")*30)
)
In this case the colors will be the same for each hour on the same day of the month, but otherwise different each day...