How can I generate a random DNA sequence?
If you want to synthesize a specific DNA sequence chemically, you start by attaching your first nucleotide (one letter in your DNA) to a solid phase. You can then continue adding individual letters to it. Because it is bound to a solid support material, you can wash the whole thing without washing your growing DNA away.

So if you want to synthesize AGC, you would first only add A to your reaction and then wash away all the A that hasn't reacted. Then you'd add G, which binds to your previous A, and again wash away all the G that hasn't reacted. Then you'd add C, and do the whole thing again.

If you want to create a random or semi-random sequence, you simply add multiple letters at once. If you always add all four letters in each step, you'll get a completely random sequence. You can also randomize only specific positions, and only there add all letters.

The result is random, but I don't think it is as random as e.g. a cryptographically secure pseudorandom number generator. There are various factors that can affect the randomness, variations in the concentrations of your nucleotides, variations in the quality or composition of your reactants and probably a lot more.  

See also Oligonucleotide synthesis on Wikipedia