I'm working (which is to say google/copy/paste/hacking) on a perl script to generate a random image for a decorative element for my website.
I've got an almost decent one going ( http://illovich.com/cgi/random_img.pl) that I'm having a problem with.... it generates the images fine (I can use that url in an image call, like and it works great, but the problem is it's using the time to generate the random number, and since I generate 5 images at a time (http://illovich.com/wp) they all come up being the same image.
Here's the basic script:
# Necessary Variables
$basedir = "http://www.illovich.com/sqicons/";
@files = ("icon1.jpg","icon2.jpg","icon3.jpg", "icon28.jpg");
srand(time ^ $$);
$num = rand(@files); # Pick a Random Number
# Print Out Header With Random Filename and Base Directory
print "Location: $basedir$files[$num]\n\n";
So I'm messing around with String::Random (http://search.cpan.org/~steve/String-Random-0.22/lib/String/Random.pm) to try to find a solution to my problem.
Basically, I need to be able to generate a random number between 1-28 that will be random enough that it will be generally 5 different results if the script is execute 5 times in a row on an html page (I'm assuming that the script I have above needs at least a milisecond if not more in between calls to get a different result on each call).
Anyway, according the the String:Random docs, I can use string_random to generate a single digit from an array, like this:
use String::Random qw(random_string);
print random_string ("0", ["1","2","3"], "\n");
...but I'm getting this error
Can't use String ("
") as an ARRAY ref while "strict refs" in use at /usr/share/perl5/String/Random.pm line 283.
I know enough to know it might be a configuration problem, but I feel like I've hit a wall with my understanding of unix, perl and all that kind of thing.
Could a kind soul point me in the right direction? =)