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 133637
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 11, 20262026-05-11T06:28:07+00:00 2026-05-11T06:28:07+00:00

How would one create a deterministic Javascript HTML colour picker which given arguments of

  • 0

How would one create a deterministic Javascript HTML colour picker which given arguments of how many colours are desired returns an array of HTML hex colour codes, ie:

    function createColours(numColours) {         return [/* colours array of size numColours */]          } 

The colours themselves can be chosen / generated randomly, but the method must guarantee that colours chosen are always the same between calls and always in the same order in series.

For example, if the series of colours decided on by the function started with the following 8:

    '#47092E', '#CC2A43', '#00C66B', '#BC1300', '#667E00', '#795800', '#FFD245', '#6EFFAD', etc, etc 

The function would behave with the following consistent responses across separate method invocations on the client

    ['#47092E', '#CC2A43'] == createColours(2);     ['#47092E', '#CC2A43', '#00C66B', '#BC1300', '#667E00'] == createColours(5);     ['#47092E'] == createColours(1);             ['#47092E', '#CC2A43', '#00C66B', '#BC1300', '#667E00', '#795800', '#FFD245', '#6EFFAD', #and 49 others#] == createColours(57);      

Note: The colours are not defined as a variable in advance; the method might be asked for 345 colours, all of which it would be required to generate by whatever suitable means.

The problem to be solved is – first and foremost – how would you create a capability within the method to generate the n HEX colour values consistently the same each time also preserving the sequence

  • 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. 2026-05-11T06:28:08+00:00Added an answer on May 11, 2026 at 6:28 am

    You need to use a pseudo random number generator (PRNG), with a fixed start seed. The Math.random method in javascript is a PRNG, but you can’t set the seed like you can in other languages.

    A PRNG is reasonably simple to create – lots of code on the internet. Given a fixed start seed it will always generate the same sequence of random numbers, which is what you’re asking for.

    Whether those colors look pleasing or not, is another question entirely…

    One javascript implementation with seeding capability:
    http://www.erikoest.dk/rng2.htm

    You’ll also find C implementations (easy to convert to javascript) and other details of building your own PRNG of the Lehmer type here:
    http://www.google.com/search?q=Lehmer%20random%20number%20generator

    Another one with code (Mersenne twister):
    http://www.math.sci.hiroshima-u.ac.jp/~m-mat/MT/VERSIONS/JAVASCRIPT/java-script.html

    This question covers several types of PRNG in javascript:
    Seedable JavaScript random number generator

    If you give the same starting seed to the PRNG at the beginning of the function, it will always return the same number sequence with each successive call.

    Convert that number into a color, and you’re all set.

    -Adam

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

Sidebar

Ask A Question

Stats

  • Questions 78k
  • Answers 78k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • added an answer Oracle themselves have a little snippet page on how it… May 11, 2026 at 3:45 pm
  • added an answer sched_setaffinity() simply tells the scheduler which CPUs is that process/thread… May 11, 2026 at 3:45 pm
  • added an answer You kind of simplified it a little too much. Autoboxing… May 11, 2026 at 3:45 pm

Related Questions

How would one create a Singleton class using PHP5 classes?
How would one create a REST web service to write a row into a
Using Django's built in models, how would one create a triple-join between three models.
I'd like to know how one would create an application that starts in the

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

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.