• Hey all, due to some issues ith some false DMCAs, we've had to censor a few things until the situation is resolved. Sorry for any inconvenience
  • Be sure to join the discussion on our discord at: Discord.gg/serebii
  • If you're still waiting for the e-mail, be sure to check your junk/spam e-mail folders

Random Code?

blueguy

used Metronome!
Hi,

I was wondering if anybody knows if there is a way to randomize coding... For example, is there a code that will allow me to enter multiple images and have one randomly appear upon each refresh?
 

Dragonfree

Just me
Well, since you're on Freewebs, you'd have to use Javascript for it...

Just do something like this where you want the image to appear (just whipped up, so it may not work perfectly):

Code:
<script type="text/javascript">
var images = new Array();

images[0] = "image1.gif";
images[1] = "image2.gif";
images[2] = "image3.gif";

// Just go on like that, always increasing the number in the []s after images

var random = Math.floor(Math.random() * (images.length - 1) + 0.5);

document.write('<img src="' + images[random] + '" alt="">');
</script>

The only part you should have to edit is the list of images...

EDIT: Tested it, and yup, it's working fine. Hope I helped.
 
Last edited:

blueguy

used Metronome!
Dragonfree said:
Well, since you're on Freewebs, you'd have to use Javascript for it...

Just do something like this where you want the image to appear (just whipped up, so it may not work perfectly):

Code:
<script type="text/javascript">
var images = new Array();

images[0] = "image1.gif";
images[1] = "image2.gif";
images[2] = "image3.gif";

// Just go on like that, always increasing the number in the []s after images

var random = Math.floor(Math.random() * (images.length - 1) + 0.5);

document.write('<img src="' + images[random] + '" alt="">');
</script>

The only part you should have to edit is the list of images...

EDIT: Tested it, and yup, it's working fine. Hope I helped.

I'll go and try this out! Thank you very much! ^_^ This was just the type of thing I was looking for. There was the same sort of code for a forum hack, but I didn't know where to find one that would work on a website.
 
Top