I’ve been trying to make a banner system that rotate every hour, but I can’t find good explanation on it. I did find a forum that said to use os.time and seed and random.new() but I didn’t understand the explanation that user provided. Could anyone explain it to me? Thanks a lot
basically you need to make sure that all servers get the same random number for the banner, so what you do is you use the hour mark as the set seed, this makes it so every server will get the same random number and you can set up the banner with that
if you want to learn more about random numbers I would recommend looking up a youtube video, Here is a brief rundown though: Random numbers generated on a computer are actually never random, they are pseudo random. What a random generated does is it takes an input for example old consoles used the run time as their random seed. the seed is then inputted into an equation which then gives an output. Another way that some random number work is that it stores huge databases of number and then you basically just go through the list of numbers in a similar fashion using the last number to help find the next.
If I use this code:
<BlockquoteBlockquote
local seed = math.floor((tick())/3600)
local RNG = Random.new(seed)
Then how would I get the unit from the RNG variable or seed variable, or is this not how you do it?
Thanks to @Inconcludable for helping me to figure this out.
He provided me with the following code which gets a random Items from the table:
local seed = math.floor((tick())/3600) * 60
local RNG = Random.new(seed)
print(seed)
local Items = {
"Item1";
"Item2";
"Item3";
}
local RandomItem = Items[RNG:NextInteger(1,#Items)]
print(RandomItem) -- Should reroll every hour
You can use this with different units stored inside a Module.
This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.