SoFunction
Updated on 2024-10-30

Example code for python color random generator

1. Code:

def random_color(number=number):
  color = []
  intnum = [str(x) for x in (10)]
  #Out[138]: ['0', '1', '2', '3', '4', '5', '6', '7', '8', '9']
  alphabet = [chr(x) for x in ((6) + ord('A'))]
  #Out[139]: ['A', 'B', 'C', 'D', 'E', 'F']
  colorArr = ((intnum, alphabet))
  #Out[142]: array(['0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'A', 'B', 'C','D', 'E', 'F'], dtype='<U1')
  for j in range(number):
    color_single = '#'
    for i in range(6):
      index = (len(colorArr))
      color_single += colorArr[index]
    #Out[148]: '#EDAB33'
    (color_single)
  return color
  del color, intnum, alphabet, colorArr, j, i, color_single, index, number
 
color = random_color(number=6)
#Out[150]: ['#81D4D4', '#70344F', '#DF91B1', '#7EE250', '#C47BC3', '#9F88D5'] 

2. Minor notes:

1. Characters to numbers ord('a') 97
Numbers to characters chr(71) 'G'

2. Difference between [ ] and ( )

((6) + ord('A'))
Out[158]: array([65, 66, 67, 68, 69, 70])
type(((6) + ord('A')))
Out[166]: 
[(6) + ord('A')]
Out[159]: [array([65, 66, 67, 68, 69, 70])]
type([(6) + ord('A')])
Out[165]: list

summarize

The above is a small introduction to the python color random generator example code, I hope to help you, if you have any questions please leave me a message, I will reply to you in time. I would also like to thank you very much for your support of my website!
If you find this article helpful, please feel free to reprint it, and please note the source, thank you!