Why do my random DNA sequences keep starting with A?

November 14, 2026 3 answers
Asked by _v38+stowmark.6

My Python function starts with an empty string and uses random.choice on G, C, A and T once per character. Six sequences in a row started with A. Is something wrong with the function?

Answers

copper+lantern_27

Nothing in that function makes A more likely at the start. Each choice has a 1 in 4 chance of being A, so six specified sequences all starting with A has a probability of 1 in 4,096, or about 0.024%. Unlikely, sure, but still possible.

Generate a larger batch and count the first letters. You should expect some variation in the counts, not exactly 25 of each in every batch of 100.

Reply to this answer
n_614~rivet

Check whether anything else in the program is calling random.seed repeatedly. The function itself doesn't reseed, and calling it quickly won't reset Python's random generator each time.

If a much larger batch still starts only with A, check the actual symbols and choice objects being used, and make sure the code being run matches the function you posted.

Reply to this answer
j5~circuit_940

Small DNA modeling note: your function makes one random strand, which is fine for what you're testing. If you want a matching second strand, use complementary bases: A pairs with T, and G pairs with C.

Reply to this answer

Add your answer

Answers are reviewed before publication.

Related Discussions