Generating a Random Hex Color in Python

前端 未结 15 1800
悲&欢浪女
悲&欢浪女 2020-11-29 01:36

For a Django App, each \"member\" is assigned a color to help identify them. Their color is stored in the database and then printed/copied into the HTML when it is needed. T

15条回答
  •  长情又很酷
    2020-11-29 02:15

    For generating random anything, take a look at the random module

    I would suggest you use the module to generate a random integer, take it's modulo 2**24, and treat the top 8 bits as R, that middle 8 bits as G and the bottom 8 as B.
    It can all be accomplished with div/mod or bitwise operations.

提交回复
热议问题