Check out a short script (from another party) to see how you can use to rename files in an ascending order. This way you can get a sense of how indexes work. I made the script below that works for me. It sets the index of the files that are in the folder. In the folder I have each file named from file1.. file2.. file3..
The script works as follows: sets the index based on the number of files, then chooses a random number between the lowest number to the index of files and then I use the GUI with "System Events" to tell terminal to open a file with the random number.
Note: I take advantage of a wonderful tool from Terminal that with tab you can finish writing to the end of the intended file so no need to type the rest. Howto link
set text item delimiters to "."
tell application "System Events"
tell application "Finder"
set all_files to every item of alias "Macintosh:Users:Home:Documents:terminal:folder3notes" as list
repeat with index from 1 to the count of all_files
set randomnumber to (random number from 2 to index)
tell application "Terminal" to activate
keystroke "open /Users/Home/documents/terminal/folder3notes/file"
key code 48