Roblox RNG Script

Posted on

RNG is the abbreviation for Random Number Generator. This one comes with a script. What is the script of RNG? Please keep reading the entire page to find out the answer to the question. If needed, you can also take a note.

You are able to find the script of Roblox RNG on a forum named devforum. Here is the script of Roblox RNG taken from the forum:

local rng = Random.new()

local function Shuffle(t)

                for i = #t, 2, -1 do

                                local j = rng:NextInteger(1, i)

                                t[j], t[i] = t[i], t[j]

                end

end


The random function takes two argument, both of them are numbers. All the numbers that you put in will be rounded to the nearest integer if it is a float. Here is the instance of generating a random integer using math.random.

 local num = math.random(1,3)

print(num)

–> 3

In this case, you are able to use the variable “num” if you want to hold a random value. For your information, the random value happened to be three. Since you have math.random() the integers 1 and 3, it generated a number from 1 to 3. You can make it more interesting and make it print something specific if the number is 1, 2, or 3.

 local num = math.random(1,3)

 if num == 1 then

                print(“Hello”)

 elseif num == 2 then

                print(“Hi there”)

 elseif num == 3 then

                print(“Good day”)

 end

–> Hi there

The script above will print a particular greeting depending on the number. This one would be good for a minigame, or something like that. Using math.random() will generate a number. However, for the format, you might put a local by math.random(5, 10). Please keep in mind that the number 5 will represent the lowest number generated, while the number 10 will represent the highest number generated. Using it is really important for games that select its own choices. Here is the way to how you can use the math.random in a brick in order to change its color.

 INPUT

local num = math.random(5,10)

if num = 5 then

script.Parent.BrickColor = BrickColor.new(“Bright red”)

if num = 6 then

script.Parent.BrickColor = BrickColor.new(“New Yeller”)

if num = 7 then

script.Parent.BrickColor = BrickColor.new(“Cyan”)

if num = 8 then

script.Parent.BrickColor = BrickColor.new(“Really red”)

if num = 9 then

script.Parent.BrickColor = BrickColor.new(“Camo”)

if num = 10 then

script.Parent.BrickColor = BrickColor.new(“Navy blue”)

OUTPUT:

The brick color will turn into “Bright red” if number was 5.

The brick color will turn into “New Yellow” if number was 6.

The brick color will turn into “Cyan” if number was 7.

The brick color will turn into “Really red” if number was 8.

The brick color will turn into “Camo” if number was 9.

The brick color will turn into “Navy blue” if number was 10.

You need to know that the math.random function is not required to be a local variable. The thing may be in a script that would not need any local variables. To do this, you need to replace your variable into math.random(low, high).

Leave a Reply

Your email address will not be published. Required fields are marked *