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
https://forums.phpfreaks.com/topic/155034-generating-and-using-random-numbers/
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.