Ruby, Generate a random hex color

后端 未结 5 573
眼角桃花
眼角桃花 2020-12-23 02:09

How can I generate a random hex color with ruby?

5条回答
  •  离开以前
    2020-12-23 02:33

    One-liner with unpack: Random.new.bytes(3).unpack("H*")[0]

    Since ruby 2.6.0 you can do it even shorter: Random.bytes(3).unpack1('H*')

提交回复
热议问题