I have a Post model with the attribute
It would be something like :
64^n - Post.count(:token).where('char_length(token) = ?', n)
The first part gives the number of combinations possible and the second the number of records with a token length of n.
But don't forget that your random generator won't necessarily generate the remaining possible combinations. There will be exponentially more and more collisions over the time, therefore I'd strongly discourage this kind of implementation.
char_length statement is MySQL specific, so depending on your RDBMS, you'll have to adapt this part.