Diese Funktion greift auf /dev/urandom zurück und generiert einen beliebigen String beliebiger Länge.
Gefüllt mit zufälligen Strings.
(Unter Windows auf irgendein Modul, Name ist mir entfallen
)
#!/usr/bin/env python
def generateHash(length):
import os
length = int(length)
try:
hash = os.urandom(length)
except NotImplementedError:
hash = None
if (hash is None):
return "Was not able to generate a hash."
else:
return hash
print generateHash("100")
Diese Funktion greift auf UUID zurück und gibt einen String bestimmter Länge aus.
php:
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
#!/usr/bin/env python
def generateHash():
import uuid
hash = uuid.uuid4()
if (hash is None):
return "Was not able to generate an id hash."
else:
return hash
print generateHash()
Ausgabe:
quote:
c94a101d-35eb-41e4-b4ed-1c1fc349a01a
Variante 3
Generiert beliebige Zahl einer beliebigen Länge.
php:
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
#!/usr/bin/env python
def generateHash(length):
import random
hash = ""
for length in range(0, int(length)):
hash += str(random.randrange(0, 10))
return hash
print generateHash("100")
If you were enjoying this post and if you keen on reading more interesting stuff then do not hesitate to complete the free sign up.
After the free registration you will gain access to all areas and you will be able to communicate with other artists from all over the world.
In addition you will benefit from our Photoshop and coding section as well as from our huge (hundreds of gigabytes) free resource section where you can find everything you will need to be a successful (web) designer/artist.
Sign up now and enjoy the advantages as a registered member.
(This website will be ad-free after a complete free sign up.)