Skip to content

Instantly share code, notes, and snippets.

@darkblue-b
Created October 19, 2013 02:36
Show Gist options
  • Save darkblue-b/7051084 to your computer and use it in GitHub Desktop.
Save darkblue-b/7051084 to your computer and use it in GitHub Desktop.
sample data with a certain distribution
import psycopg2
import random
conn = psycopg2.connect( 'dbname=ta_test' )
curs = conn.cursor()
tSQL_create0 = '''
drop table if exists tta cascade;
create table tta ( tta_item integer, pkey serial);
'''
curs.execute(tSQL_create0)
for tInd in xrange(100000):
tD = int(random.random() * 12)
if tD > 3:
tIters = 1
else:
tIters = tD + 2
for x in xrange(tIters):
curs.execute( 'INSERT into tta (tta_item) VALUES ({0})'.format(tInd) )
if tInd % 10000: conn.commit()
conn.commit()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment