The title may be a bit broad. Not just any random value, but, within a certain range. Like, from [2] to [5].
Question1 = {"What is the best pie?","Apple","Blue","Red","Green"} print(Question1[math.random(#Question1)]) -- a little help here?
To choose a random element from a specific range just change the numbers in the math.random
function.
Question1 = {"What is the best pie?","Apple","Blue","Red","Green"} print(Question1[math.random(FirstIndex,LastIndex)]) --Change FirstIndex and LastIndex
Alternatively you could write a function
function Random(tab,x,y) return tab[math.random(x,y)] end Random({"Hi","Nope","Yes"},2,3) --return random value between index 2 and 3
Your script is correct, now, to make it go from a certain range, it's just like doing math.random(1,5)
, let me show you;
Question1 = {"What is the best pie?","Apple","Blue","Red","Green"} --Heres your original table print(Question1[math.random(2,#Question1)]) --This will choose one string randomly from the table [between 2-Number in Table 'Question1' [in this case, 'Apple' to 'Green']]; look closely, and there is a '2'! :D
Hope this helped!