Hi there, I’ve made a little module script that allows you to generate a lot of stuff just like vector3 or color3, It’s based on the Unity Random Class of course I’ve added few features that are relative only to the Roblox studio.
Here are few examples of the usage:
Examples
Example of usage of CustomRandom.RandomMaterial()
--Require Module - https://www.roblox.com/library/6254550249/Random
local CustomRandom = require(6254550249)
local IS = game:GetService("UserInputService")
--You can easily generate materials for the part
local part = Instance.new("Part")
part.Parent = workspace
part.Anchored = true
IS.InputBegan:Connect(function(key)
if key.KeyCode == Enum.KeyCode.Space then
part.Material = CustomRandom.RandomMaterial()
end
end)
Example of usage of CustomRandom.valueInt()
--Require Module - https://www.roblox.com/library/6254550249/Random
local CustomRandom = require(6254550249)
--You can easily make a rarity system
for i = 0, 10, 1 do
local value = CustomRandom.value()
if value > 0.9 then
print("rare thing happen")
else
print("Nothing special happen")
end
end
Example of usage of CustomRandom.insideUnitSphere()
--Require Module - https://www.roblox.com/library/6254550249/Random
local CustomRandom = require(6254550249)
local RS =game:GetService("RunService")
--You can easily spawn stuff near a point
local part = Instance.new("Part")
part.Parent = workspace
part.Anchored = true
for i = 0, 1000, 1 do
local a = Instance.new("Part")
a.Anchored = true
a.Position = CustomRandom.insideUnitSphere() * 50
a.Parent = workspace
a.Shape = Enum.PartType.Ball
local b = CustomRandom.Range(1, 5)
a.Size = Vector3.new(b, b, b)
a.Color = CustomRandom.RandomColor3()
a.Material = CustomRandom.RandomMaterial()
end
Here are all of the methods of the module and their description:
Methods
RangeInt(min, max) - Returns an int that is smaller than max but bigger than min
Range(min, max) - Returns a number that is smaller than max but bigger than min
valueInt() - Returns 0 or 1
value() - Returns a number that is smaller than 1 but bigger than 0
InsideUnitCircle() - Returns a point in a circle with a radius of 1
insideUnitSphere() - Returns a point in a sphere with a radius of 1
RandomColor3 - Returns a random Color3
RandomMaterial() - Returns a random EnumItem.Value
InsideUnitCube() - Returns a random point in a cube with a size of 1
OnUnitSphere() - Returns a random point on a sphere with a radius of 1
How to get it:
I’ve uploaded it to the Roblox library so you can just do something like this:
local CustomRandom = require(6254550249)
or
https://www.roblox.com/library/6254550249/Random
or
Update 1
- Added Linear congruential generator
- Fixed minor bugs
- Finally formatted code
It’s my first module even published and I’m looking for good feedback on it and suggestions.