RANDOM is not available in all shells. I know for sure it is there in ksh/sh,not there in csh/tcsh. Since its working on your prompt, try to run your script in the same shell as is your command line.
Thanks. It fixes the immediate problem, but I'm curious as to why the RANDOM variable doesn't work inside the script, and I didn't fully understand the symlink explanation. Can you elaborate?
To paraphrase the earlier poster, when you type "sh" in your particular version of Linux you actually get "dash" because "sh" is a symbolic link to "dash".
In your case you probably needed to specify "bash".
In older unixes "sh" gave you the Bourne Shell but in most modern mainstream unixes "sh" gives you the Posix Shell. There is even more variation in Linux.
@eclipseagent - My code was the same as yours and wasn't working. I finally realized that I had been forgetting to do `chmod +x <filename>'! It works now. Thanks for helping me work out such an obvious error