Is there any possible way to create random numbers for game objects?

is there any possible way to create random numbers for game objects?

How do you mean? There’s math.random() that will produce random numbers.

well i’m creating magic triangle game so i want to create random numbers but in assending order

like this. This is a demo game im trying to make game like this…

1 Like

First, use the random function with a seed depicting the largest possible number that you would like to get. Use it to fill up a table. Afterwards, you might want to write your own sorting function, for 6 numbers, you should be okay with the good old bubble sort

Obviously, it is a good idea to check if it is at all possible to combine the numbers and obtain the end result. From the screenshot that you have posted, I cannot understand how the game ought to work. Does it work in a similar way as a Pascal’s triangle (as in you combine numbers from lower tiers to compute numbers on upper tiers)?

Thanks…but if I use math.Random() means it will give same numbers for multiple times…So how to slove that…?

Instead of randomizing the number you can randomize the number interval:

local numbers = {}
local next = 0
for i = 1,6 do
	next = next + math.random(1, 10)
	table.insert(numbers,next)
end
pprint(numbers)	
DEBUG:SCRIPT: 
{
  1 = 2,
  2 = 5,
  3 = 12,
  4 = 13,
  5 = 16,
  6 = 20,
}
3 Likes

in that Example your giving interval for numbers?

Yes, it’s really simple:

  1. Start with 0 and store the value
  2. Add a random number to the stored value
  3. Goto 2

So you randomize the interval between each number. That gives random numbers which are already sorted.

2 Likes

Okay thanks…