Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

How can I cause BrickColor.Random() to have a different seed?

So I have been wanting to set a players team color to a random color when they get a team. So I did some research and found BrickColor.Random(). I am concerned that this Roblox function does not have a great random algorithm. Because of this I was wondering if I could use something like the Random object:

local ran = Random.new()
local ranNum = ran:NextInteger(1, 5)

except with BrickColors. However I don't know how I would do this. Also I think that the color property of a team must be a BrickColor. If not please tell me because that would make things so much easier. Here is my code in case you were wondering:

								local team = Instance.new("Team")
								local teamColor 
								
								repeat 
								
									teamColor = BrickColor.Random()
								
								until noTeamColorMatch(teamColor)
								
								team.TeamColor = teamColor
								team.Name = plr.Name.."'s Castle"
								team.Parent = teams
								plr.Team = team

Thanks!

1 answer

✓ Accepted answer

Hello Phlegethon5778,

You can do this two ways.

The first would be to use the BrickColor.new() with a Color3 value.

The second would be to use the BrickColor.palette function.

Both work, however the first way might be slightly more efficient, and I'll show you why:

function getRandomBrickColor()
	local color3 = Color3.fromRGB(math.random(0,255),math.random(0,255),math.random(0,255))

	local brickColor = BrickColor.new(color3)

	return brickColor
end

This function generates a random color3, and then transfers it into a BrickColor.

The next function makes a table of BrickColors and then picks a random one.

local brickColors = {}

function getRandomBrickColor()
	local brickColor = brickColors[math.random(0,#brickColors)]
end

for paletteIndex = 0, 127 do
	table.insert(brickColors,BrickColor.palette(paletteIndex))
end

And there's our two methods of getting a random brick color.

This should be pretty straight forward, but if you've got any questions, feel free to ask!

3 comments

0

But how does the first method create a BrickColor with random RGB values?

0

Maybe try BrickColor.palette(int paletteValue) (0-127) with a random value? Not sure if this is > brickColor.random...

0

I figured your answer out now. I don't think it is worth it for what I am doing. However thanks for the amazing answer and I may be able to use this in my future work.

This discussion is preserved as it was. New answers, comments, and votes are closed.