If you theorize that gender depends on the ending, you run into inconsistencies because gender is often determined by semantic content:
Cardinal directions are masculine (der Norden)
Letters of the alphabet are neuter, (das A ind das O)
Numbers are feminine, (die Eins, die Zwei)
Oceans are masculine (der Atlantik)
Continents are neuter (rarely used with an article)
Minerals are neuter (das Salz)
Spices are masculine (der Paprika, der Pfeffer)
Vegetables are neuter (das Paprika)
Verbal nouns that indicate an instance of the action are masculine and usually have an ablaut: (Der Fall, der Flug)
Verbal nouns that are things that perform the action are feminine: (Die Falle, die Fliege)
Verbal nouns that indicate the process of performing the action are neuter: (Das Fallen, das Fliegen)
Rivers inside the area settled by the ancient Germanic tribes, which was offset east of where it is now, are feminine (die Weichsel) and those outside are are masculine (der Rhein, der Mississippi)