how to use Random for two sets of numbers?

Hello

i have two sets of numbers, lets say 1,2,3 and 5,8,10

how can i use Random.Range to get a random number from 1,2,3 or 5,8,10

A simple method is to make a list… and add to that list all the numbers you want to be possibly generated…

Then generate a random integer between 0 and the last element of the list…

And return the contents of the list at that index.

I would create a list with them. I’m relatively new at lists and haven’t used them much but I would try to do something like this:

public int GetANumber()
{
List<int> numbers = new List<int>();
numbers.Add(1);
numbers.Add(2);
numbers.Add(3);
numbers.Add(5);
numbers.Add(8);
numbers.Add(10);
int length = numbers.Count;
int random = Random.Range(0,length);
return numbers[random];
}

The section where I add the numbers you listed manually would need to be replaced with whatever you need to do to get the numbers you have into the list. So if you have two arrays you need to loop through them and add all the values to the list.