예제 #1
0
def pgtest(tuple, seed=None):
    print tuple
    pg = pghash.pghgen(joiner=m2, seed=seed)
    rng = pg.hash(tuple)
    print m2(tuple)
    print rng.hex
    if rng.hex in hashes:
        print "Duplicate hash!"
    hashes.append(rng.hex)
    print rng.gauss(0, 1)
    print rng.gauss(100, 10)
    print rng.random()
    print rng.choice(three)
    print rng.choice(four)
    print rng.choice(eight)
    print rng.choice(twelve)
    print rng.choice(twentysix)
    print rng.choice(many)
import pghash
import random

pg = pghash.pghgen()

outFile = open("pghash_bytes", "wb")

for x in range(0, 1000000):
    char = pg.hash((x, )).randint(0, 255)
    hexx = chr(char)
    outFile.write(hexx)

outFile.close()

print "pghash_bytes done"

outFile = open("random_bytes", "wb")

for x in range(0, 1000000):
    char = random.randint(0, 255)
    hexx = chr(char)
    outFile.write(hexx)

outFile.close()

print "random_bytes done"
예제 #3
0
import pghash
import time

seed = 123
mv = 1

pg = pghash.pghgen(seed=seed)

t = time.time()
for x in range(0, 1000000):
    mv = min(mv, pg.hash((x, )).random())
print time.time() - t

print mv
import pghash
import string
from collections import defaultdict

f1 = lambda t: '{' + sep.join(map(str, t)) +'}' if hasattr(t, '__iter__') else str(t)
m1 = lambda t: sep.join(map(f1, t))

three=('a','b','c')
four=('a','b','c','d')
eight=('a','b','c','d','e','f','g','h')
twelve=('a','b','c','d','e','f','g','h','i','j','k','l')
twentysix=('a','b','c','d','e','f','g','h','i','j','k','l','m','n','o','p','q','r','s','t','u','v','w','x','y','z')
many=('a','b','c','d','e','f','g','h','i','j','k','l','m','n','o','p','q','r','s','t','u','v','w','x','y','z','z','z','z','z','z','z','z','z','z','z','z','z','z','z','z','z','z','z','z','z','z','z','z','z','z','z','z','z','z','z','z','z','z','z','z','z','z','z','z','z','z','z','z','z','z','z','z','z','z','z','z','z','z','z','z','z','z','z','z','z','z','z','z','z','z','z','z','z','z','z','z','z','z','z','z','z','z','z','z','z','z','z','z','z','z','z','z','z','z','z','z','z','z','z','z','z','z','z','z','z','z','z','z')

results = defaultdict(int)
pg=pghash.pghgen(joiner='{:}')

def pgtest(tuple):
    rng=pg.hash(tuple)
    randint = rng.randint(1,100)
    results[randint] += 1

for c1 in string.ascii_lowercase:
    for c2 in string.ascii_lowercase:
        for c3 in string.ascii_lowercase:
            pgtest((c1,c2,c3))

for k in sorted(results.keys()):
    print k, results[k]