Jump to content

Generating and using random numbers


alex3

Recommended Posts

I have two images I want to load from a folder of images, these images must match. The syntax of the image files names is headerpX.png and footerpX.png. I'd like a random set of these images to load every page load. Here's how I think might be a good way to do it n very pseudo-code

 

$1 get number of files in images/ folder
$2 get the integer of ($1/2)
$3 get random number between 1 and $2

 

And then in my HTML code, I'd have the code

 

<img src="images/headerp$3.png"></img>
<img src="images/footerp$3.png"></img>

 

(or however I'd embed that random number in to the src field)

 

Is this do-able and easy code? Will the $3 number be the same if I call it twice in the HTML, or will it run the javascript again and return a different random number?

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.