Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

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

Asked by 5 years ago

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

Log in to vote
1
Answered by
Eqicness 255 Moderation Voter
5 years ago

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!

0
But how does the first method create a BrickColor with random RGB values? User#21908 42 — 5y
0
Maybe try BrickColor.palette(int paletteValue) (0-127) with a random value? Not sure if this is > brickColor.random... ABK2017 406 — 5y
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. User#21908 42 — 5y
Ad

Answer this question