The targets were not picked at random.
The Atomic Bombings of Hiroshima and Nagasaki by The Manhattan Engineer District, June 29, 1946. The Selection of the Target. Some of the most frequent queries concerning the atomic bombs are those dealing with the selection of the targets and the decision as to when the bombs would be used.
www.atomicarchive.com
That resulted in the selection of 5 possible targets for the first mission - Hiroshima, Yokohama, Kokura, Niigata and Kyoto. The last was ruled out by Stimson. Hiroshima was picked as the primary target. For the second mission, Kokura was the primary target but by the time the B-29 Bockscar reached it, smoke for fires elsewhere were covering the aiming point. So the aircraft diverted to the secondary target, Nagasaki.
Once Truman gave the order to drop the bombs, actual target selection and timing was in the hands of the military. Planning for a third drop was underway with aircraft of the 509th back in the USA collecting components. They were planning that third drop for around 19 Aug.
With negotiations with the Japanese beginning around 10 Aug, Truman rescinded the previous orders and took full control of all future A bomb missions on 12 Aug, suspending plans for the third drop.