Skip to content
Browse files

added more files for plotting primes, randoms, generating randoms wit…

…h probability similar to primes
  • Loading branch information...
1 parent 9953dd6 commit 6c345148158200cd5448fe900132afc8e98c2c51 @stevekochscience committed Jun 13, 2012
Showing with 452 additions and 1 deletion.
  1. +21 −0 rand_pp.py
  2. +21 −0 rand_pp.py~
  3. +1 −1 trinum.py
  4. +41 −0 trinum.py~
  5. +24 −0 trinum1.py
  6. +46 −0 trinum_coord.py
  7. +46 −0 trinum_coord.py~
  8. +40 −0 trinum_coord_b.py
  9. +40 −0 trinum_coord_b.py~
  10. +46 −0 trinum_coord_rand.py
  11. +46 −0 trinum_coord_rand.py~
  12. +40 −0 trinum_rp.py
  13. +40 −0 trinum_rp.py~
View
21 rand_pp.py
@@ -0,0 +1,21 @@
+#public domain
+#This file will generate a list of numbers which have about the same
+#density as the prime numbers, but based on random.random() function
+
+import math
+import random
+
+SIZE = 510510
+
+outfile = open('pr%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\n" %i)
+ else:
+ pass
+
+outfile.close()
+
View
21 rand_pp.py~
@@ -0,0 +1,21 @@
+#public domain
+#This file will generate a list of numbers which have about the same
+#density as the prime numbers, but based on random.random() function
+
+import math
+import random
+
+SIZE = 9699690
+
+outfile = open('pr%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\n" %i)
+ else:
+ pass
+
+outfile.close()
+
View
2 trinum.py
@@ -3,7 +3,7 @@
# 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
-SIZE = 30000
+SIZE = 510510
BLANK = " "
B = 5
View
41 trinum.py~
@@ -0,0 +1,41 @@
+# 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
+SIZE = 9699690
+BLANK = " "
+B = 5
+
+#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 primes rows
+
+cc = 0 # column count
+lc = 0 # line count
+
+outfile = open('pt%d.txt' %SIZE, 'w')
+
+for i in range(2,SIZE):
+ if i in p:
+ # print repr(i).rjust(B),
+ outfile.write(repr(i).rjust(B))
+ else:
+ # print BLANK,
+ outfile.write(BLANK)
+
+ cc += 1
+ if cc == p[lc]:
+ lc += 1
+ cc = 0
+ #print
+ outfile.write('\n')
+ else:
+ pass
+
+outfile.close()
+
View
24 trinum1.py
@@ -0,0 +1,24 @@
+p = []
+f = open("p3000.txt")
+
+for line in f:
+ p.append(int(line))
+
+cc = 0
+lc = 0
+
+for i in range(2,200):
+ if i in p:
+ print repr(i).rjust(3),
+ else:
+ print " ",
+
+ cc += 1
+ if cc == p[lc]:
+ lc += 1
+ cc = 0
+ print
+ else:
+ pass
+
+
View
46 trinum_coord.py
@@ -0,0 +1,46 @@
+# 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)
+
+SIZE = 510510
+BLANK = " "
+B = 5
+
+#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 primes rows
+
+cc = 0 # column count
+lc = 0 # line count
+
+outfile = open('ptc%d.txt' %SIZE, 'w')
+
+for i in range(2,SIZE):
+ if i in p:
+ # print repr(i).rjust(B),
+ outfile.write("%d,%d,%d\n" %(i, cc, lc))
+ # outfile.write(repr(i).rjust(B))
+ else:
+ # print BLANK,
+ #outfile.write(BLANK)
+ pass
+
+ cc += 1
+ if cc == p[lc]:
+ lc += 1
+ cc = 0
+ #print
+ #outfile.write('\n')
+ else:
+ pass
+
+outfile.close()
+
View
46 trinum_coord.py~
@@ -0,0 +1,46 @@
+# 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)
+
+SIZE = 510510
+BLANK = " "
+B = 5
+
+#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 primes rows
+
+cc = 0 # column count
+lc = 0 # line count
+
+outfile = open('ptc%d.txt' %SIZE, 'w')
+
+for i in range(2,SIZE):
+ if i in p:
+ # print repr(i).rjust(B),
+ outfile.write("%d,%d,%d\n" %(i, cc, lc))
+ # outfile.write(repr(i).rjust(B))
+ else:
+ # print BLANK,
+ #outfile.write(BLANK)
+ pass
+
+ cc += 1
+ if cc == p[lc]:
+ lc += 1
+ cc = 0
+ #print
+ #outfile.write('\n')
+ else:
+ pass
+
+outfile.close()
+
View
40 trinum_coord_b.py
@@ -0,0 +1,40 @@
+# 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)
+
+SIZE = 510510
+
+#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 primes rows
+
+cc = 0 # column count
+lc = 0 # line count
+
+outfile = open('ptcb%d.txt' %SIZE, 'w')
+
+for i in range(2,SIZE):
+ if i in p:
+ outfile.write("%d,%d,%d\n" %(i, cc, lc))
+ else:
+ pass
+
+ cc += 1
+ if cc >= lc:
+ lc += 1
+ cc = 0
+ #print
+ #outfile.write('\n')
+ else:
+ pass
+
+outfile.close()
+
View
40 trinum_coord_b.py~
@@ -0,0 +1,40 @@
+# 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)
+
+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 primes rows
+
+cc = 0 # column count
+lc = 0 # line count
+
+outfile = open('ptcb%d.txt' %SIZE, 'w')
+
+for i in range(2,SIZE):
+ if i in p:
+ outfile.write("%d,%d,%d\n" %(i, cc, lc))
+ else:
+ pass
+
+ cc += 1
+ if cc >= lc:
+ lc += 1
+ cc = 0
+ #print
+ #outfile.write('\n')
+ else:
+ pass
+
+outfile.close()
+
View
46 trinum_coord_rand.py
@@ -0,0 +1,46 @@
+# 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()
+
View
46 trinum_coord_rand.py~
@@ -0,0 +1,46 @@
+# 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()
+
View
40 trinum_rp.py
@@ -0,0 +1,40 @@
+# this small python program makes a textfile that prints out
+# [random fake prime] numbers in rows of increasing size. the size of
+# each row increases with size being the next [random fake prime] number
+# i created this program to see if I see patterns when printing
+# [random fake prime] numbers this way
+
+SIZE = 510510
+
+# First, read in the primes
+# This is not efficienct and slows down when I try SIZE = 9699690 (19#)
+# I need to combine sieve.py and this file so make a generating function
+# that does everything
+p = []
+f = open("pr%d.txt" %SIZE) #this file is generated by rand_pp.py
+for line in f:
+ p.append(int(line))
+
+#Next, print out primes rows
+
+cc = 0 # column count
+lc = 0 # line count
+
+outfile = open('prt%d.txt' %SIZE, 'w')
+
+for i in range(2,SIZE):
+ #print "i is %d" %i
+ if i in p:
+ 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()
+
View
40 trinum_rp.py~
@@ -0,0 +1,40 @@
+# this small python program makes a textfile that prints out
+# [random fake prime] numbers in rows of increasing size. the size of
+# each row increases with size being the next [random fake prime] number
+# i created this program to see if I see patterns when printing
+# [random fake prime] numbers this way
+
+SIZE = 510510
+
+# First, read in the primes
+# This is not efficienct and slows down when I try SIZE = 9699690 (19#)
+# I need to combine sieve.py and this file so make a generating function
+# that does everything
+p = []
+f = open("pr%d.txt" %SIZE) #this file is generated by rand_pp.py
+for line in f:
+ p.append(int(line))
+
+#Next, print out primes rows
+
+cc = 0 # column count
+lc = 0 # line count
+
+outfile = open('prt%d.txt' %SIZE, 'w')
+
+for i in range(2,SIZE):
+ print "i is %d" %i
+ if i in p:
+ 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()
+

0 comments on commit 6c34514

Please sign in to comment.
Something went wrong with that request. Please try again.