Permalink
Switch branches/tags
Nothing to show
Find file
Fetching contributors…
Cannot retrieve contributors at this time
47 lines (36 sloc) 1.07 KB
# This is a companion program to trinum_coord.py that makes a point
# randomly, instead of based on whether it's prime. info for
# companion file follows:
# this small python program makes a textfile that prints out
# prime numbers in rows of increasing size. the size of
# each row increases with size being the next prime number
# i created this program to see if I see patterns when printing
# prime numbers this way
# this is based on trinum.py but will output coordinates for
# graphing (such as in R)
import math
import random
SIZE = 30000
#First, read in the primes
p = []
f = open("p%d.txt" %SIZE) #this file is generated by sieve.py
for line in f:
p.append(int(line))
#Next, print out the coords
cc = 0 # column count
lc = 0 # line count
outfile = open('ptcr%d.txt' %SIZE, 'w')
for i in range(2,SIZE):
ran = random.random()
prob = 1.0 / math.log(i)
if ran < prob:
outfile.write("%d,%d,%d\n" %(i, cc, lc))
else:
pass
cc += 1
if cc == p[lc]:
lc += 1
cc = 0
else:
pass
outfile.close()