I believe that Photoshop really needs the ability to add "variable tokens" into the filename. The tokens are not literal characters, they are metacharacters that the save naming routine would "translate" into literal characters. The token could also offer parameters, such as the number of digits required.
As an example, the filename entry could be:
My great digital painting_\\random-digits,6\\
And when saved as say a JPEG the result would be:
My great digital painting_542876.jpg
In this example, I have used illegal filename characters \\ as "reserved" special characters to designate the token. This is just an example, more commonly this would be { } or double-escaped {{ }} or [ ] or [[ ]] etc.
There could be a checkbox to enable tokens, or a preference setting. It would be helpful that there was a option in the GUI to select and insert the token rather than relying on the user to type it correctly. This should also be supported by actions and script.
An ExifTool example;
https://exiftool.org/filename.html
Here is an example from XnConvert which has this option for adding text as an overlay to images: