And i'am sure it will work great!
Here is the .htaccess directives responsible to pass the actual .html page's absolute path to counter.py (please do not get mad at me, i'am trying to code your solution into python code, which is easier to me)
RewriteEngine On
RewriteCond %{HTTP_HOST} ^(www\.)?superhost\.gr$
RewriteCond %{REQUEST_FILENAME} -f
RewriteRule ^/?(.+\.html) /cgi-bin/counter.py?htmlpage=%{REQUEST_FILEN
+AME} [L,PT,QSA]
But my friend, why bother creating a custom function?
Wouldn't something like the following work as intended?
pin = int( htmlpage.encode("hex"), 16 ) % 10000