Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 1097517
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 17, 20262026-05-17T00:26:43+00:00 2026-05-17T00:26:43+00:00

I need to randomly generate colors for multiple items in a to do list.

  • 0

I need to randomly generate colors for multiple items in a to do list.

(like pick up the kids from school, pick up the dry cleaning and so on)

What’s the best way of doing this in ruby and also avoid colors that would be hard to see (like grey, white, and so on)?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-17T00:26:44+00:00Added an answer on May 17, 2026 at 12:26 am

    Using RGB you will have harder times avoiding gray colors, as well as colors “difficult to see” (I’m guessing on a white background)

    If you need them to be random, you can use HSV values to stay away from the white, gray and black spectra. That means you set a range in the value and saturation parameters (for example, ~175 to 255) while hue can be selected freely at random.

    So, this may work:

    def random_bright_color(threshold = 175)
      hue = rand(256 - threshold) + threshold
      saturation = rand(256 - threshold) + threshold
      value = rand(256)
      hsv_to_rgb(hue, saturation, value)
    end
    

    where

    def hsv_to_rgb(h, s, v)
      if s == 0
        r = g = b = (v * 2.55).round
      else
        h /= 60.0
        s /= 100.0
        v /= 100.0
    
        i = h.floor
        f = h - i
        p = v * (1 - s)
        q = v * (1 - s * f)
        t = v * (1 - s * (1 - f))
        rgb = case i
          when 0 then [v, t, p]
          when 1 then [q, v, p]
          when 2 then [q, v, t]
          when 3 then [p, q, v]
          when 4 then [t, p, v]
          else        [v, p, q]
        end
      end
      rgb.map{|color| (color * 255).round}
    end
    

    is ported from here and the explanation can be found on the same Wikipedia article


    However, if you additionally need to have random colors different from each other, perhaps the really true solution is to have them selected from a group of base colors, and select at random from that set.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.