math.random()

• In computing it is impossible to create random numbers, some ways are better than others but in roblox people would normally use math.random() because of its simplicity and that is what we will be covering today.

math.random() normally has two arguments within its brackets m and n. When both numbers are passed it will return a random number between the two numbers. For example math.random(17,36)
might return 22. If only m is passed then it will return a random number from 1,m. If nothing is passed it will return a number from 0,1.

To select a random item from an array you could do this:
num = math.random(1,#array) #array is used to tell you how many are in that array.
item = array[num] [ ] allows you to select an item in the list from where it's position is on a list.
This is a practical use of math.random().

You can use math.random() for many things as you can see a, random map chooser a random player chooser or you can use it to program random items which spawn in a game. This is one of the most useful things in programming and is very simple to use.

Shabbs15

• @shabbs15 It is possible to create a "random" number but you would use something other than time, an examples is HDD noise.

For Roblox I would use `wait()`

``````local tm = 0
for i=1, 10 do
tm = tm + wait(wait())
end

print(tm)
``````

Something like this should be ok to use as a seed.

• I THINK what your doing is more random but you can not and never will be able to make it completely random.

• You should call math.randomseed (tick()) at the beginning of any Script that uses math.random() to make math.random() much more random. wiki.roblox.com

Looks like your connection to Scripting Helpers was lost, please wait while we try to reconnect.