The fedora is not randomly generated.
Due to its lack of special ability, AC benefits and even sale value, the Archeologist's starting fedora is often ditched near the beginning of the game for the first (usually metallic) helm the player finds.
The fedora is introduced in NetHack 3.0.0.
The fedora is a felt hat with a wide brim (about 2.5 inches or 6.4 cm) and a distinctive lengthwise crease in the crown; the style goes back as far as the 1880s. The name is derived from the 1882 Victorien Sardou play Fedora, in which actress Sarah Bernhardt (whom the play was written for) wore one while playing the titular "Princess Fedora"; the term itself would see regular use as the early 1890s. Fedoras were especially popular from the 1920s to the early 1950s, and fell out of widespread fashion after the mid-1950s - they are still occasionally seen worn as accessories in the modern day.
The Indiana Jones franchise is first set in 1936, and is significantly inspired by Secret of the Incas and its main character, Harry Steele - the fedora's inclusion in NetHack is part of the Archeologist role's homage to the series.
Some variants play up the Indiana Jones homage further by making the fedora function similar to a luck item.
In UnNetHack, the fedora increases base Luck by 1 for Archeologists when worn; they can also safely enchant one at a maximum of +5. In addition, a fedora may be found along with an archeologist corpse under a rolling boulder trap.
In xNetHack, Archeologists can safely enchant fedoras from a maximum of +5, and there is a chance to find one on an archeologist corpse in the path of a rolling boulder trap - both changes were adapted from UnNetHack.
In addition to SLASH'EM details, SlashTHEM incorporates the biodiversity patch, including straw golems dropping an eroded fedora upon death.
In Hack'EM, upgrading a fedora will produce an elven helm and vice versa, as in SLASH'EM.
Some hats can only be worn if you're willing to be jaunty, to set
them at an angle and to walk beneath them with a spring in your
stride as if you're only a step away from dancing. They demand a
lot of you.
[Anansi Boys, by Neil Gaiman]