I'm not sure what the question is. Can you not just split the first line at the spaces, count the length of the array, then use randint(0,9) (or whatever range you want) to create an array of equivalent length and write that back into your file?
–
MoritzAug 20 '12 at 10:05

Sorry, I'm just trying to clarify. What part is confusing?
–
Kathryn BradleyAug 20 '12 at 10:09

Well, what you are describing: "I get that I should feed the first column into an array, index each one and then randomly swap out" sounds correct. So are you asking for help on how specifically to implement this (i.e. sample code) or do you want to know how to insert the column back into the file? I guess I'm just confused as to where exactly the problem is, as the approach you are describing sounds like it would work.
–
MoritzAug 20 '12 at 10:23

Yeah, I understand how I should implement it because I've programmed in C before, but I have no idea how to write it in python (so I'm looking for references/sample code). Thanks :)
–
Kathryn BradleyAug 20 '12 at 10:30

Okay, thanks, I'll have a go. I don't need to generate a random string, I need to replace strings in the first column with another specified string, for example replacing Zr with O twice out of 100 occurences (I'm dealing with atoms here!)
–
Kathryn BradleyAug 20 '12 at 10:13