Wednesday, April 23, 2008

Ya'll are so jealous

The following took about 7 hours of work:


# establish variables
words=[1,2,3,4]
w_order=[]
choosei=[]
choosej=[]
import random
random.shuffle(words)

#the main randomizer loop
for i in range(283):
choosei = words[2]
w_order.append(choosei)
words.pop(2)
choosej=words[2]
words.pop()
w_order.append(choosej)
words.append(choosei)
choosei = words[1]
w_order.append(choosei)
words.append(choosej)
words.pop(1)
random.shuffle(words)
words.append(choosei)
#print results
print w_order

#print the counts of all syllables
a = w_order.count(1)
b = w_order.count(2)
c = w_order.count(3)
d = w_order.count(4)
total = a+b+c+d
print a,b,c,d,total

#convert all values in w_order to strings
pw_order = str(w_order)

#write the word order results to a file

outfile = open('/Users/pacatrue/Desktop/orderresults.txt','w')
for line in pw_order:
outfile.write(line)
outfile.close()



Isn't it beautiful? It generates a random string of 849 numbers between 1 and 4 with the condition that no number can immediately repeat. Here's the stunning output:


[2, 4, 3, 4, 3, 1, 3, 1, 2, 1, 2, 3, 1, 3, 4, 3, 4, 2, 1, 2, 4, 3, 4, 2, 1, 2, 4, 1, 4, 2, 3, 2, 1, 4, 1, 3, 2, 3, 4, 2, 4, 3, 1, 3, 2, 1, 2, 4, 1, 4, 3, 4, 3, 1, 4, 1, 2, 4, 2, 3, 1, 3, 4, 2, 4, 1, 3, 1, 2, 1, 2, 3, 1, 3, 4, 3, 4, 2, 3, 2, 1, 3, 1, 2, 1, 2, 4, 3, 4, 2, 3, 2, 1, 3, 1, 4, 2, 4, 3, 4, 3, 1, 2, 1, 4, 1, 4, 2, 3, 2, 4, 1, 4, 2, 1, 2, 4, 3, 4, 1, 2, 1, 3, 1, 3, 2, 4, 2, 1, 4, 1, 3, 2, 3, 1, 2, 1, 4, 1, 4, 2, 4, 2, 1, 3, 1, 4, 3, 4, 1, 3, 1, 2, 4, 2, 1, 2, 1, 4, 3, 4, 2, 4, 2, 1, 4, 1, 3, 1, 3, 2, 4, 2, 3, 2, 3, 1, 3, 1, 4, 3, 4, 1, 4, 1, 2, 3, 2,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2, 3, 1, 3, 2, 4, 2, 3, 4, 3, 1, 2, 1, 3, 4, 3, 1, 3, 1, 2, 3, 2, 1, 4, 1, 3, 1, 3, 2, 4, 2, 1, 2, 1, 4, 2, 4, 1, 3, 1, 4, 2, 4, 3, 1, 3, 4, 3, 4, 2, 1, 2, 4, 1, 4, 3, 4, 3, 1, 2, 1, 3, 4, 3, 1, 4, 1, 3, 2, 3, 4, 3, 4, 2, 1, 2, 4, 2, 4, 3, 2, 3, 1, 2, 1, 4, 2, 4, 1, 2, 1, 3, 1, 3, 2, 3, 2, 4, 2, 4, 3, 4, 3, 1, 4, 1, 3, 4, 3, 1, 3, 1, 4, 2, 4, 3, 1, 3, 2, 1, 2, 3, 2, 3, 1, 3, 1, 2, 1, 2, 4, 2, 4, 3, 1, 3, 4, 1, 4, 2, 3, 2, 1, 3, 1, 4, 2, 4, 1, 4, 1, 3, 1, 3, 4, 3, 4, 1, 4, 1, 3, 2, 3, 1, 2, 1, 4, 1, 4, 2, 4, 2, 3, 4, 3, 2, 1, 2, 4, 2, 4, 1, 2, 1, 3, 2, 3, 4, 2, 4, 3, 4, 3, 1, 3, 1, 2, 1, 2, 4, 3, 4, 1, 2, 1, 4, 1, 4, 2, 1, 2, 3, 4, 3, 2, 4, 2, 3, 4, 3, 2, 4, 2, 3, 4, 3, 2, 1, 2, 3, 2, 3, 4, 2, 4, 1, 3, 1, 2, 4, 2, 3, 2, 3, 4, 1, 4, 3, 4, 3, 1, 3, 1, 4, 3, 4, 1, 4, 1, 3, 2, 3, 1, 4, 1, 3, 2, 3, 4, 1, 4, 2, 3, 2, 1, 3, 1, 4, 3, 4, 1, 3, 1, 4, 2, 4, 3, 2, 3, 1, 4, 1, 3, 1, 3, 4, 1, 4, 2, 4, 2, 3, 4, 3, 1, 2, 1, 3, 2, 3, 4, 1, 4, 3, 1, 3, 4, 1, 4, 3]

Aren't you all so jealous that you can't be in grad school creating strings of random numbers?! I know it.

By the way, what this is about is that I'm creating an artificial language for an experiment and I have to randomize (under certain conditions) the word order. I couldn't find any way to do this with the pre-built programs, so I had to program it myself. This is the Python programming language. I didn't know any Python before having to solve this task, so I spent tons of time with tutorials to pull off this little program. This is one of the things making be stress out a couple days ago.

3 comments:

Precie said...

Ah.

I was wondering what programming had to do with linguistics. Why on earth are you creating an artificial language?

And, to play devil's advocate, aren't all languages artificial? ;)

Good luck with your project!

ChristineEldin said...

I could've let you copy mine. If you had asked, you know.
:-)

Precie said...

Bhahahaha! Good one, chris!