Nature Photographers Network
This is the preserved archive of the original Nature Photographers Network. The community continues at naturephotographers.network.

Is there a mathmatician in the house?

Discussion

3 replies
Posted by Curtis Knight on September 2, 2007 at 1:38 PM
Hi guys, this isn't quite as off-topic as it sounds. The front page image rotation is a java script, and the randomizer code has a couple bugs.

occasionally the page comes up with no image at all, and other times it'll repeat the same image 2 or 3 times. I realize that there is no such thing as a truely random number, but there should be a way to prevent a "null" result, which is what I think is happening when the page comes up without an image.

Anyway, If there's anyone who could help with the code, it would be greatly appreciated. you can email me at curtis@cascademountainphotography.com

Thanx!
-CK
Posted by michael medina on September 2, 2007 at 3:41 PM
you probably need a javascripter more than a math dood, but i would look around the web for another script, maybe at dynamicdrive.com or any of the other great resources out there. most won't provide a null result and i've seen some that have a setting to prevent the same image twice, but i think those use a cookie.
Posted by Bryan Swan on September 3, 2007 at 1:28 AM
You'll have to run an if / else statement. Basically you need to ask it to check to see if the random number is a valid number, and then if it is, it needs to return the number. The script should look something like this:

if rand(100) isNAN {
return () }
else { return rand(100) }

Assuming you want a random number between 1 and 100. This may or may not work, my javascript is rusty (plus its probably the most aggravating web programming language to write in).

*EDITED*

Two other things just popped into my mind that you might want to check. Have the randomizer code print out the number and see if you can't see what number is being generated when it comes up with no picture - that way you can test to see if its the code or the URL of the image that is screwing it up.

Second, using the rand() function, I don't think you even have to use the isNAN function to check the validity of the number, so you might just be able to do something like this (again don't copy verbatim, it probably won't work):

(in the header)
randomNumber = rand(100);
imageURL = filepath/.print(randomNumber).'.jpg';
(end header)

(html body)
img src="j avascript:print(imageURL);"
^ but without the space because the word "j avascript" won't show up if I don't put the space in there for some oddball reason. This forum software is a tad outdated, imo.
Posted by Curtis Knight on September 3, 2007 at 2:25 AM
Thanks guys! The guy who wrote the script contacted me and pointed out a typo I had in my image list that was causeing the problem.

Thanks for the responses!