I am trying to make a kind of color generator for a single seed, so u would type in 482 or something and get a few random colors. I have made this kind of work with brick color but I want to use all the colors so someone please help me.
You would probably do something similar to what @VegetationBush suggested. You could generate the R, G, and B values separately, then combine them.
function RandomColor(Seed)
local Generator = Random.new(Seed)
local R = Generator:NextInteger(0, 255)
local G = Generator:NextInteger(0, 255)
local B = Generator:NextInteger(0, 255)
return Color3.fromRGB(R, G, B)
end
I did try that however, because of how RGB works you would have to use 3 different seeds, if you try to use the same seed (what I want to do) you end up with a black and white color.
After trying this function in studio, it generates a unique R, G, and B value for the color (works as expected!). It is because of the Random object. The Random object has a function NextInteger() that can generate a random number using the previous random number generated as the seed, so we should only need one initial seed (as shown by the above function with only one argument, Seed)
It’s the easiest and probably the most efficient way.
local function colors(Seed)
math.randomseed(Seed) -- set the seed
return Color3.new(math.random(), math.random(), math.random())
math.randomseed(os.time()) -- reset it
end
This works because math.random() without any paramters returns a value from 0 to 1, which also happens to be the number range that Color3.new() accepts. and math.randomseed() just sets the seed to that.
In this case I think using Random is suggested over math.random/math.randomseed, because randomseed is global and affects any other scripts using it, while Random is local only.
I think you’re misunderstanding what it’s doing. It is using one seed and generating multiple numbers from it. The sequence of numbers that come out will always be the same due to the starting seed.
For example if you do local R = Random.new(2090435), then the next 3 times you call R:NextInteger(0, 255), the same 3 numbers will come out (26, 32, 59).
Random only generates numbers. So you have to use those numbers to create a Color3 manually.