I suspect that it's much like the immune system. For example, antibody diversity is "generated by DNA rearrangements during B-cell development".[0] And:[1]
> In another parallel with the immune system, cadherin-related neuronal receptors (CNRs) are diversified synaptic proteins. The CNR genes belong to protocadherin (Pcdh) gene clusters. Genomic organizations of CNR/Pcdh genes are similar to that of the Ig and TCR genes. Somatic mutations in and combinatorial gene regulation of CNR/Pcdh transcripts during neurogenesis have been reported.
So as with evolution, more-or-less random variation generates diversity in the developing nervous system. And then there's selection.
> In another parallel with the immune system, cadherin-related neuronal receptors (CNRs) are diversified synaptic proteins. The CNR genes belong to protocadherin (Pcdh) gene clusters. Genomic organizations of CNR/Pcdh genes are similar to that of the Ig and TCR genes. Somatic mutations in and combinatorial gene regulation of CNR/Pcdh transcripts during neurogenesis have been reported.
So as with evolution, more-or-less random variation generates diversity in the developing nervous system. And then there's selection.
0) https://www.ncbi.nlm.nih.gov/books/NBK27140/
1) https://www.ncbi.nlm.nih.gov/pubmed/12558794