Believe me, it's been thought of (it's been in my head ever since my colleague Frank Seide introduced me to RNNs 4 years ago, I'm sure I wasn't the first!). It is one thing to generate code that looks like code, quite another to generate code that is useful. Character-by-character probably isn't good enough for this task.
Anyways, I talk about how to use probability (but not compute it!) in http://research.microsoft.com/pubs/179363/mcdirmid12.pdf