LuaTex (or whoever) is searching for randqs.lua in the directory of the .tex file rather than in the directory of the .sty file because if the .lua is in the former then it is found, while if it is in the latter then it is not. I'm guessing that dofile is not the way to go here, so my question is: how do I ensure that LuaTex (or whoever) looks for the file in the .sty directory rather than the .tex directory?

A third option is to locate the file using kpse library, e.g. dofile(kpse.find_file("randqs.lua")).
–
Khaled HosnyOct 26 '12 at 20:43

@KhaledHosny, topskip: Thank you both, after refreshing my file name database, both the kpse.find and require methods work. Is there any reason to prefer one to the other?
–
Scott H.Oct 26 '12 at 21:40

@ScottH.: I’m not sure, require() looks cleaner, but kpse.find_file() might give you a bit more control on how to locate the files (LuaTeX manual gives more details on what options you can pass to it).
–
Khaled HosnyOct 27 '12 at 22:55