954,549 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Have something to say? Contribute New Article Reply to this Article

Random backgrounds

i have a bunch of images

1.jpg, 2.jpg etc..

I have a class called banner and wondering how to get it to randomised threw the pics?

Thanks

namit
Light Poster
44 posts since Jun 2005
Reputation Points: 10
Solved Threads: 0
 

read the filenames into a List, generate a sequence of random numbers, et voila.

jwenting
duckman
Team Colleague
8,392 posts since Nov 2004
Reputation Points: 1,662
Solved Threads: 337
 

but have ya got any examples of this?

namit
Light Poster
44 posts since Jun 2005
Reputation Points: 10
Solved Threads: 0
 

You should be able to defer the code from what I wrote.
It's simple really.

List map = new ArrayList();
// loop through files
while (files.hasNext()) {
  map.add(files.next());
}

or something like that.
That's of course not complete code but should serve as a starting point ;)

jwenting
duckman
Team Colleague
8,392 posts since Nov 2004
Reputation Points: 1,662
Solved Threads: 337
 

Use a Random object or something:

Random random = new Random(2);

int rotation = random.nextInt()+1;

server_crash
Postaholic
2,111 posts since Jun 2004
Reputation Points: 113
Solved Threads: 20
 

This article has been dead for over three months

Post: Markdown Syntax: Formatting Help
You