How to randomize an array selection??

Hey, I created an array with a bunch of images and programmed it to randomly select one of them. It works fine, except the first one is always the same everytime I restart the app.

Here’s my code:

 array= {}  
local i = 1  
array[i]= display.newImage("frasefinal/Slide01.png");array[i].alpha=0;i=i+1   
array[i]= display.newImage("frasefinal/Slide02.png");array[i].alpha=0;i=i+1   
array[i]= display.newImage("frasefinal/Slide03.png");array[i].alpha=0;i=i+1   
array[i]= display.newImage("frasefinal/Slide04.png");array[i].alpha=0;i=i+1   
array[i]= display.newImage("frasefinal/Slide05.png");array[i].alpha=0;i=i+1   
array[i]= display.newImage("frasefinal/Slide06.png");array[i].alpha=0;i=i+1   
array[i]= display.newImage("frasefinal/Slide07.png");array[i].alpha=0;i=i+1   
array[i]= display.newImage("frasefinal/Slide08.png");array[i].alpha=0;i=i+1   
array[i]= display.newImage("frasefinal/Slide09.png");array[i].alpha=0;i=i+1   
array[i]= display.newImage("frasefinal/Slide10.png");array[i].alpha=0;i=i+1   
  
function selectimage()  
local randomimage = math.random(1,#array)  
  
--1 to highest index in the table  
 array[randomimage].alpha=1  
 array[randomimage].x = \_W/2  
 array[randomimage].y = \_H/2 - 30  
 array[randomimage]:setReferencePoint(display.CenterReferencePoint)  
   
  
end  
  
  
selectimage()   
  

Any thoughts on how to randomize even the first one?
Thanks [import]uid: 95495 topic_id: 17879 reply_id: 317879[/import]

Do you use math.randomseed(os.time()) anywhere in your code? If not, adding it on the top of the code may just fix it for you. (But if you already use this random seed function, I have no clue how to fix your issue.)

Naomi [import]uid: 67217 topic_id: 17879 reply_id: 68249[/import]

It worked thanks a lot!!! [import]uid: 95495 topic_id: 17879 reply_id: 68250[/import]

Great!
Naomi [import]uid: 67217 topic_id: 17879 reply_id: 68267[/import]