Firing order is defined by the crankshaft in a two-stroke and the crankshaft plus the cam shaft(s) in a four-stroke. In a two-stroke near top dead center on every rotation and in a four-stroke near top dead center on every other rotation. As for what might work best when there are options... That's a completely different issue. A two-cylinder, four-stroke, opposed engine in a BMW motorcycle fires both cylinders simultaneously to minimize the side-to-side effect like sloshing. A two-cylinder, four-stroke V Harley-Davidson engine fires 1-2-skip-skip, resulting in a bone-shaking vibration. Check out a flat four VW Beetle engine vs. a flat four Corvair vs. a flat four Subaru vs. an inline four Datsun. Different designs are a tradeoff between reciprocating vibration and the vibration due to firing and compression and is a decision based on particular preferences. Some people like the Harley-Davidson vibrations and think the look-alike, smooth-running Japanese copycat motorcycles are pathetic. There is no "fixed formula" because there is no single criterion for what constitutes "best".
It is highly recommended that you use ChatGPT as an assistant. You can find your answer or it provides you with some clues so that you can find the exact answer with high accuracy.
This is easier to address if we know what kind of engine you are working on. I am going to assume you are working with a 4-stroke engine but is it an inline 4 cylinder, inline 6 cylinder, V-6 or possibly a V-8.
Inline 4-cylinder engines very often use a 'flat plane' crank with cylinders 1 and 4 traveling in unison and 2 and 3 in unison. This lends itself well to a 1-3-4-2 firing order. (notice an outside-inside-outside-inside pattern) There are a few oddball cranks but this covers 98.5% of them. A drawback to the 4-cylinder flat crank it that two pistons are at TDC when two are at BDC so all four pistons are changing direction at the same time.
Inline 6-cylinders have 1-6, 2-4, 3-4 travelling in pairs with the pairs separated by 120 degrees on the crank. Firing order is universally 1-5-3-6-2-4. I expect there is an inline 6 out there that does not follow that rule but in 45 years I have not seen it.
V6 it gets a little more confusing at the engines can be either 60 degree or 90 degree Vees each having advantages and disadvantages. Different manufacturers also number their cylinders differently making a standard arrangement more difficult to simply state.
V8 are a little more standardized than V6. Most V8 use a 90 degree crankshaft on a 90 degree V. General motors tends to number their cylinders 1-3-5-7 front to back on the left side and 2-4-6-8 front to back on the right side. There are alternative firing orders but a very common on with that arrangement is 1-8-4-3-6-5-7-2. You have to draw it out to see how the cylinders 'hit' side to side and front to back. There are some other firing orders out there but that is most common. With the theory that various first and second order harmonics are better controlled, regardless of how many cylinders you have.
In all cases, the cam has to be ground so that the valves are behaving appropriately for whatever firing order you are working with.
So, yes, way down in engine design there are some guidelines for setting up a firing order. I have never seen a specific formula for creating a firing order mostly guidelines as very few of us are going to be able to just go whip up a different crankshaft because we feel like trying something.
You had asked about a source. A 'problem' with sources is that much of this was established 100 years ago. Then, the more cylinders you have, the more degrees of freedom you have. I also have not really addressed differences between even fire (a 4 cylinder that has a power stroke every 180 degrees) vs odd fire (think Harley Davidson or Ducati 2 cylinder engines that have irregular gaps between power strokes)
A place to get started with documentation might be Blair, Gordon P, Design and Simulation of Four Stroke Engines, Society of Automotive Engineers, Inc, Warrendale, PA. 1999. ISBN 0-7680-0440-3 Specifically, Chapter 5 around pages 530 enters into a discussion on cylinder numbering and firing orders. There are numerous references at the end of the chapter that may offer more illumination.