Generate a random hex code (color) in under 400 characters

Asked Sep 3, 2022·2 replies·Last activity 3 years ago·Open in Discord ↗
Archived from the original community forum
Things may have changed since it was written. Still stuck? Ask the community on Discord.

I made this:

#$(eval var sayings = ['0','1','2','3','4','5','6','7','8','9','A','B','C','E',"F"]; sayings[Math.floor(Math.random() * sayings.length)];)$(eval var sayings = ['0','1','2','3','4','5','6','7','8','9','A','B','C','E',"F"]; sayings[Math.floor(Math.random() * sayings.length)];)$(eval var sayings = ['0','1','2','3','4','5','6','7','8','9','A','B','C','E',"F"]; sayings[Math.floor(Math.random() * sayings.length)];)

which gives me the 3 out of the 6 values but then I hit the character limit and can't complete the command.

This is code I've seen for picking a random number between 1 and 1,000,000 ten times:

$(eval x=`;for(a=0;a<10;a++){y=Math.floor(Math.random()*1000000)+1;x+=y+ `}x)

But it's all numbers and the code I'm using has numbers AND letters

2 replies

Hey @Amiable Wolf!

You can just use the same array and random-pick function multiple times:

$(eval o = ['0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'A', 'B', 'C', 'D', 'E', 'F']; r = (a) => a[Math.floor(Math.random() * a.length)]; `#${Array.from({length: 6}, () => r(o)).join('')}`;)

Be careful to use the proper quote marks: ' instead of ‘’, or " instead of “”.
Also, you had forgotten D.

Amazing and perfect, thank you!!