Re: Math.random()




maya wrote:
maya wrote:
Jeff Higgins wrote:
Daniel Pitts wrote:
maya wrote:
(I want to have option of displaying photos in a random order instead
of in order of img-names (1.jpg, 2.jpg, 3.jpg, etc..))

Try putting the photos into a List object, and then calling
Collections.shuffle() with that list object as the parameter.

A clear winner. :-))


ok, am trying to do this now.. acc to docs it's like a vector except
"synchronized" (not sure what this means..) only thing in Vector you add
elements thus:

vPhotos.addElement(imgsList[i]);

but am having problems here:

ArrayList photos = new ArrayList(); File directory = new
File(System.getProperty("user.dir"));
String[] textFileNames = directory.list(new FilenameFilter() {
public boolean accept(File dir, String name) {
return name.endsWith(".jpg") || name.endsWith( ".JPG");
}
});
for (int i=0; i < textFileNames.length+1; i++) {
photos.add(i); // error here...

photos.add(new File(i));

}


how do I convert this "i" to an object (since this method takes only obj
as argument..)

and then how do I apply Collections.shuffle() to it??

photos.Collections.shuffle() ?? I dont think so....;)

I really need this today, for some photos I'm putting together for a
friend overseas, sending with a friend who travels today....

thank you very much..



ok, I think got Collections.shuffle() part..

Collections.shuffle(photos, new Random());

only problem now is how to add all nos. to ArrayList (this has to be 1.4
construction, not 1.5..)

and then how to go from Collections.shuffle to this:

for (int i = 0; i < textFileNames.length; ++i) {
File oldFile = new File(textFileNames[i]);
posDot = textFileNames[i].indexOf(".");
_temp = textFileNames[i].substring(0,posDot);
File newFile = new File(i+1 + ".jpg");
oldFile.renameTo(newFile);
}

so imgs are named with nos. at random (i.e., so imgs, after renamed, are
in diff order from orig ones..)


thank you....



.



Relevant Pages

  • Re: Math.random()
    ... Try putting the photos into a List object, and then calling Collections.shufflewith that list object as the parameter. ... only problem now is how to add all nos. ... so imgs are named with nos. ...
    (comp.lang.java.help)
  • Re: Math.random()
    ... Try putting the photos into a List object, and then calling Collections.shufflewith that list object as the parameter. ... String[] textFileNames = directory.list{ ... I really need this today, for some photos I'm putting together for a friend overseas, sending with a friend who travels today.... ...
    (comp.lang.java.help)
  • Re: Math.random()
    ... Daniel Pitts wrote: ... Try putting the photos into a List object, and then calling ... Collections.shufflewith that list object as the parameter. ...
    (comp.lang.java.help)
  • Re: Enicar Sherpa Jet repaired by expert.
    ... Someone on ebay is selling one NOS and asking ... 80+ year old acquaintence who is a competent watch `hobbyist' ... I posted new photos, showing the process and details of the ...
    (alt.horology)
  • Re: For Sale prototype # 007 White Water (last call before Mr Pin and Ebay)
    ... I'd be interested in photos. ... Shipping would be required. ... If these NOS parts were put in- that would be back in 1993- correct? ... Marc B ...
    (rec.games.pinball)