Have the CGI program create the link as well, and it can pass the previous roll as a parameter.
Note that this isn't really a Perl question, you'd have a similar problem (and solution) if you had programmed this in C, Python, Java or some other language.
Comment on Re: saving a random number while generating a new one