How can I create and validate against a url token?
My first problem is, I haven't figured out how to properly escape the anchor parameter.


I'm guessing you mean the link is being escaped (since Twig will do that by default) and you don't want it to?  If so, you can use the |raw filter (http://twig.sensiolabs.org/doc/filters/raw.html).


  My second problem is how to generate a random token. I'd like to generate a random string or something.


If you don't care if it's a cryptographically secure string, you can just use StringHelper::randomString() or StringHelper::UUID().  If you want a cryptographically secure random string, then you can use craft()->security->generateRandomString().