How are military aircraft numbered?
At present, all US military aircraft follow the 1962 United States Tri-Service aircraft designation system. The first letter ('F' or 'B') denotes the mission of the aircraft, while the number denotes the design number. The designation system produces a Mission-Design-Series (MDS) designation. From Designating and Naming Military Aerospace Vehicles:

4.1. Designator Definition:
4.1.1.The  MDS designator is an official DoD recognized alpha-numeric symbol designation of a military defense aerospace vehicle. .... The designator describes the aerospace vehicle in two components where the components are separated by a hash.The first component, comprised  only  of  alpha characters, describes the mission of the vehicle.The second component, comprised of both alpha-numeric characters, describes the design number and design series of the vehicle.
4.1.2. Standard  aircraft MDS designators are comprised of the following: status prefix(optional), modified mission(optional), basic mission(required), design number (required), design series (required).

The document also gives some examples of this implemenatation:


Both tables from Designating and Naming Military Aerospace Vehicles
The 1962 system replaced the earlier system, where each service had their own systems in place for naming of aircraft.

From 1924 - 1962, the USAF (and the USAAF before them) used the 1924 United States Army Air Service aircraft designation system.

During the same time, the USN used the 1922 United States Navy aircraft designation system.

Once the USAF was formed from the USAAF in 1947, the US Army followed the 1956 United States Army aircraft designation system till 1962.

Before all of these was the 1919 United States Army Air Service aircraft designation system.


More details about the aircraft designation can be found in this page.
Basically, the counters were reset while the 1962 sytem was adopted, leading to unrelated sets of aircraft numbering. As for individual aircraft numbering, there has been a number of cases where the system was not followed, like the F-117 Nighthawk.
Adherence to this system has been patchy at best. So, you have B-1 Lancer and B-2 Spirit after B-52 Stratofortress (this was due to the counters being reset), while the next bomber has been named B-21 Raider.