Reputation: 1
How would I generate random (R,G,B) colors with minimum components of .5 in a tuple? I'm new at this and fairly confused.
Upvotes: 0
Views: 1106
Reputation: 155353
Since this is a homework assignment, it's probably best to avoid just giving you the answer, so here's some basics. You can make a tuple
with commas (parens only needed when commas might have other meanings, e.g. in function calls, literals of other types, etc., or when the lack of parens would lead to incorrect order of operations), so to make a tuple
of three elements, you can just do:
threetup = a, b, c # Or (a, b, c)
where a
, b
, and c
can be replaced with any source of a value.
For generating the random RGB components, I suggest you take a look at the random
module, specifically random.uniform
for getting random floating point values.
Upvotes: 2
Reputation: 23104
Somthing like this:
import random
def rand_color():
return "#" + "".join(random.sample("0123456789abcdef", 6))
You need to take care of the ".5 minimum" requirement.
Upvotes: -1