Call Random Pictures
I'm trying to create an app that each time someone want to go to a new picture, it calls up a random one so that each time they are in the app, it is a different experience.
Does anyone know of any sample code for this to work?
2 Answers
-
Create it yourself, it shouldn't be hard. Use filesystem to get the names of the image files, then randomly select them using rand or some other method.
-
Just download this function:
http://phpjs.org/functions/rand:498
Call your images 0.png 1.png 2.png etc
Then use something like this:
var rondomnumber = rand(0,(20-1)); //change 20 to the amount of images you have var tabs3 = Titanium.UI.createButton( //or something else then a button... { backgroundImage: randomnumber+'.png' }