This is a read-only snapshot of the ComputerCraft forums, taken in April 2020.
roger109z's profile picture

Convert 1-16 to color decimal

Started by roger109z, 14 December 2016 - 12:33 AM
roger109z #1
Posted 14 December 2016 - 01:33 AM
basically I am making a random number from 1-16 and I want to convert it to the decimal for colors.
Dog #2
Posted 14 December 2016 - 01:54 AM
I *think* what you want is something like this…

local myColor = 2 ^ (math.random(1, 16) - 1)

I *believe* you can simplify that by doing this if you don't require 1-16, but I haven't tested it…

local myColor = 2 ^ math.random(0, 15)