Is it possible to assign a random color to a font?

  • Hello,

    I am working on a report for which one of its requirements is that at the beginning of each year, the font color in one of its sections changes automatically.

    I am not sure if this is possible, I have search, found and read a few examples and they all have the colors to use for the switch, hard coded, and it only shows 3-5 colors.

    Does anyone know how to achieve something like this?

    I hope my question is formatted correctly, I am just trying to gather some ideas.

    Thank you,

    itortu

  • One (stupid) idea. Use RAND with a seed, to create a known "random" number, convert that to a Hex value and then use that.

    For example, take the following SQL:

    USE Sandbox;
    GO

    SELECT RAND(CONCAT(V.Yr,'0101')),
    CONVERT(varbinary(3),RAND(CONCAT(V.Yr,'0101'))),
    CONVERT(varchar(6),CONVERT(varbinary(3),RAND(CONCAT(V.Yr,'0101'))),2) AS HexColour
    FROM (VALUES(2019),
    (2020),
    (2021))V(Yr);

    This results in the hex values 243C92, E135AA, and EC51D6, which gives you these "lovely" colours:

    Thom~

    Excuse my typos and sometimes awful grammar. My fingers work faster than my brain does.
    Larnu.uk

  • I'd be concerned about generating a random color that was too close to the background color and difficult to read. What if you picked, say, 20-30 colors ahead of time that you know will work and put them in a table with a year associated with them. When the report runs, you could pick the color associated with that year and know that you had a color that would be readable on the report.

Viewing 3 posts - 1 through 2 (of 2 total)

You must be logged in to reply to this topic. Login to reply