"Michael Bay" Transformers can choose any form, but there is a size/mass limitation.
In the Michael Bay movies, Transformers have an existing robot mode and personality, but can at any time scan a vehicle to use as an alt mode. Their robot mode "armor" changes to accommodate this new form, but the underlying robot's appearance and mass are basically unchanged. Presumably this requires some extra energy and effort on the Transformer's part, so they don't do it very often.
However, mass shifting doesn't exist in the Michael Bay movies, so presumably Transformers need to choose vehicle modes that are similar in size and mass to their current robot form. Jazz could not have scanned and adopted the form of a large truck, and Optimus Prime could not have duplicated a sports car. Within those limitations, though, personality becomes the driving factor. Jazz's personality was such that given an entire showroom of GM vehicles to choose from, he picked the most prominent and stylish one.
Other Transformers series have dealt with the question in different ways.
In some iterations of the cartoon (Beast Wars and Robots in Disguise come to mind), unformed Transformers exist in what's called a "protoform" status, hidden away inside a cocoon and apparently formless. The protoform scans a vehicle (or an animal, or a fossil, or even, in the case of Robots in Disguise Scourge, a human, truck and Autobot all at the same time) and uses that as a template for its robot and alt mode as well as its personality. No mass shifting takes place; a protoform that scanned a small rat would transform into a gigantic rat (Beast Wars Rattrap).
In the original G1 cartoon, Transformers need to be physically rebuilt in order to adopt a new alt mode, and thus their alt modes were chosen for them by whoever was doing the rebuilding.