Ever wanted to add some randomised spice to your games? Well I did for approximately 5 minutes before I realised a customer wouldn’t like a product with random tweens.
Anyway, this module returns a completely random EasingStyle for your tweens, instead of the usual boring ones you may have.
This doesn’t really serve a huge purpose, however it’s quite cool!
Code
local module = {}
function module:getRandomTweenMethod(): Enum.EasingStyle
local easingStyles = {
Enum.EasingStyle.Linear,
Enum.EasingStyle.Sine,
Enum.EasingStyle.Quad,
Enum.EasingStyle.Cubic,
Enum.EasingStyle.Quart,
Enum.EasingStyle.Quint,
Enum.EasingStyle.Exponential,
Enum.EasingStyle.Circular,
Enum.EasingStyle.Back,
Enum.EasingStyle.Bounce,
Enum.EasingStyle.Elastic
}
math.randomseed(os.time())
local style = easingStyles[math.random(1, #easingStyles)]
return style
end
return module
function getRandomStyle(): Enum.EasingStyle
local styles = Enum.EasingStyle:GetEnumItems()
math.randomseed(os.time())
return style[math.random(1, #styles)]
end
this way you don’t create an array every time the fn is called + your code is shorter!
local EasingStyles = Enum.EasingStyle:GetEnumItems()
local EasingCount = #EasingStyles
local gen = Random.new(os.clock() * 2048)
local function NextStyle()
return EasingStyles[gen:NextInteger(1, EasingCount)]
end