After doing a bunch of tests I have found out that this is the “best” way to generate a random RGB color, but I still think that there might be a better way, if so could someone tell me what it would be?
local function rc()
local colorhex = math.random(16^6)-1
local b=bit32.extract(colorhex,0,8)
local g=bit32.extract(colorhex,8,8)
local r=bit32.extract(colorhex,16,8)
return Color3.fromRGB(r,g,b)
end
I used to do that, but I’m using my new method since its a bit faster. I’m also guessing that there is no better way to generate a color than what I have right now unless a lua wizard or smth shows up.
local t1 = os.clock()
for i = 1, 100000, 1 do
local colorhex = math.random(16^6)-1
local b=bit32.extract(colorhex,0,8)
local g=bit32.extract(colorhex,8,8)
local r=bit32.extract(colorhex,16,8)
local color = Color3.fromRGB(r,g,b)
end
print(os.clock() - t1)
local t2 = os.clock()
for i = 1, 100000, 1 do
local color = Color3.fromRGB(math.random(1,255),math.random(1,255),math.random(1,255))
end
print(os.clock() - t2)
Thats why it is in a function and its not that unreadable, but I do get why people would prefer other methods over this since the speed difference is not that big.