Click here to Skip to main content
15,896,207 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
The whole thing really is what im wondering about, first time doing this without for with for and so on generating all combinations.

"""Dont know how to check for errors numerically because of to many iterations
or how to check by derivation proof
"""

from random import randrange

"""Random rgb color combination
0<=red<=255
0<=green<=255
0<=blue<=255
Supposed to be all combinations of integers from span above
255**3
"""
def Random_Rgb():
    a = randrange(0,255**3+1,1)
    red=0
    green=0
    blue=0
    #One red cycle
    while a >= 255**2:
        a -= 255**2 
        red += 1
    #Green cycles
    while a >= 255:
        a -= 255
        green += 1
    green += (red*255)%255
    #Blue cycles
    while a >= 1:
        a -= 1
        blue += 1
    blue += (red*255*255)%255 + (green*255)%255
    return red, green, blue

red, green, blue = Random_Rgb()
print(red,green,blue)


What I have tried:

Numerically: wrapping in for, too many iterations
Proof: I barely understand combinatorics: The form on wich its stated is confusing to me also too much text in online guides I loose track so instead i tinkered with combinatorics but i dont feel the least bit sure the code is right
Posted
Updated 13-Apr-20 21:22pm

1 solution

This is really all you need
Python
for i in range(10):    # set loop count to however many samples you want
    red = random.randrange(256)
    green = random.randrange(256)
    blue = random.randrange(256)
    print("Colour:", red, green, blue)
 
Share this answer
 
Comments
Maciej Los 14-Apr-20 5:43am    
5ed!
Richard MacCutchan 14-Apr-20 6:12am    
Thanks, but nothing very clever.
Maciej Los 14-Apr-20 6:18am    
Sometimes, "nothing very clever" is a cause of someone's pain. ;)
The point of view depends on seat - as we say in Poland. I don't know proper English version.
[EDIT]
I was trying to tell that, the obvious things are not so obvious to everyone.
I hope it clarifies my previous statements.
Tjohohan 14-Apr-20 11:23am    
Thank you:)

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900