Premium Necro 78 Posted November 11, 2014 Premium Share Posted November 11, 2014 Hi guys, i have problem. I need function which show me 1 from 10 names. parex. - with number it is local numbers = number(1, 9) and system choose one number of them but i need this with words so something like local names = name(dog, dog1, dog2, dog3, dog4) and system choose one of them. Any ideas? Link to comment Share on other sites More sharing options...
Premium Sanchez 2464 Posted November 11, 2014 Premium Share Posted November 11, 2014 You can do it easily without any help, just build the pseudo code in your head: - You have a list which contains elements, each element have an index - You can get the size of the array by using the table.getn(ListName) function - You can use the math.random(1, list_size) function to generate a random number between the given range - You can get an element from the list by an index So how it looks overall: -- Initialize the list DestList = { Dog, Elephant, Cat, Parrot, Monkey } -- Get a random index between 1 and the length of the array local randomValue = math.random(1, table.getn(DestList)) -- Print the element at the given index: print(DestList[randomValue]) 1 Link to comment Share on other sites More sharing options...
Premium Necro 78 Posted November 11, 2014 Author Premium Share Posted November 11, 2014 Thank you Link to comment Share on other sites More sharing options...
Recommended Posts
Please sign in to comment
You will be able to leave a comment after signing in
Sign In Now