PDA

View Full Version : Random number checking problem



asylum24
December 3rd, 2004, 11:15 AM
well here is my code that I have


shuffle=Math.ceil(Math.random()*2)
shuffle2=Math.ceil(Math.random()*4)
if(shuffle==1){
shuffle="hawaii";
}
if(shuffle==2){
shuffle="ua";
}

gallery_stage.loadMovie("pictures/" + shuffle + shuffle2 +".jpg");

trace(shuffle + shuffle2);


that works all fine and dandy except that i have these pictures and there are 4 hawaii pictures and only 2 ua pictures. and it loads everything correectly but whenever shuffle = something more than 2 and shuffle = 2 (like if shuffle =2 and shuffle2 = 4, it owuld load ua4.jpg, which doesnt exist) so how can I check to see if it is there and if its not, redo shuffle2?

anyhelp would be appreciated.

asylum24
December 3rd, 2004, 01:38 PM
no ebcuase im not loading it into seperate movie clips its randomly picking if its a hawaii or a ua picture and hten randomly picking which picture it is with shuffle 2. and then combining the two to give me the file name which loads it into gallery_stage. its for a random background and hten im using the same pictures through out the site taht way i dont have to load the same picture again with just a diff. filename.

stringy
December 3rd, 2004, 02:41 PM
no ebcuase im not loading it into seperate movie clips its randomly picking if its a hawaii or a ua picture and hten randomly picking which picture it is with shuffle 2. and then combining the two to give me the file name which loads it into gallery_stage. its for a random background and hten im using the same pictures through out the site taht way i dont have to load the same picture again with just a diff. filename.

try something like this

createEmptyMovieClip("gallery_stage", 1);
myArray = [];
for (var i = 1; i<5; i++) {
myArray.push("hawaii"+i);
}
delete i;
for (var i = 1; i<3; i++) {
myArray.push("ua"+i);
}
function shuffle() {
return Math.round(Math.random());
}
myArray.sort(shuffle);
gallery_stage.loadMovie("pictures/"+myArray[0]+".jpg");

asylum24
December 3rd, 2004, 04:18 PM
iono. im at home now and just arted typing stuff out and I think I came up with a solution.... tell me what youthink

shuffle=Math.ceil(Math.random()*2)

//declares how many pictures there are of (n) type
numOfPicsUA = 2;
numOfPicsHaw = 4;





if(shuffle==1){
shuffle="hawaii";
shuffle2=Math.ceil(Math.random()*numOfPicsHaw)
}

if(shuffle==2){
shuffle="ua";
shuffle2=Math.ceil(Math.random()*numOfPicsUA)
}

gallery_stage.loadMovie("pictures/" + shuffle + shuffle2 +".jpg");

trace(shuffle + shuffle2);