I'm having the same problem on a new Mac Studio with two identical Samsung monitors connected via Thunderbolt to DisplayPort cables. They look lovely and run at 144Hz, but switch sides randomly on every wake from sleep. I tracked down how to extract the EDID info, and it's very simple in a terminal:
ioreg -l | grep EDID
For me this shows my two monitors:
| | | | "DisplayAttributes" = {"SupportsSuspend"=No,"MaximumRefreshRate"=144,"SupportsActiveOff"=No,"PortID"=32,"ProductAttributes"={"ManufacturerID"="SAM","YearOfManufacture"=2018,"SerialNumber"=810889805,"ProductName"="C27JG5x","AlphanumericSerialNumber"="HTOKC02346","LegacyManufacturerID"=19501,"ProductID"=3928,"WeekOfManufacture"=51},"MaxVerticalImageSize"=34,"MaxHorizontalImageSize"=60,"HasHDMILegacyEDID"=No,"Chromaticity"={"Red"={"X"=44352,"Y"=20736},"Green"={"X"=18048,"Y"=43328},"Blue"={"X"=9984,"Y"=4032}},"DefaultColorSpaceIsSRGB"=No,"NativeFormatHorizontalPixels"=2560,"DefaultWhitePoint"={"X"=20544,"Y"=21568,"Gamma"=144179},"SupportsVariableRefreshRate"=No,"AspectRatio"=15,"MinimumRefreshRate"=50,"WhitePoints"=({"X"=20544,"Y"=21568,"Gamma"=144179}),"PreciseAspectRatio"=115652,"ContinuousFrequencySupport"="None","SupportsStandby"=Yes,"NativeFormatVerticalPixels"=1440}
| | | | "EDID UUID" = "4C2D580F-0000-0000-331C-0104A53C2278"
| | | | "DisplayAttributes" = {"SupportsSuspend"=No,"MaximumRefreshRate"=144,"SupportsActiveOff"=No,"PortID"=48,"ProductAttributes"={"ManufacturerID"="SAM","YearOfManufacture"=2018,"SerialNumber"=810889805,"ProductName"="C27JG5x","AlphanumericSerialNumber"="HTOKC02337","LegacyManufacturerID"=19501,"ProductID"=3928,"WeekOfManufacture"=51},"MaxVerticalImageSize"=34,"MaxHorizontalImageSize"=60,"HasHDMILegacyEDID"=No,"Chromaticity"={"Red"={"X"=44352,"Y"=20736},"Green"={"X"=18048,"Y"=43328},"Blue"={"X"=9984,"Y"=4032}},"DefaultColorSpaceIsSRGB"=No,"NativeFormatHorizontalPixels"=2560,"DefaultWhitePoint"={"X"=20544,"Y"=21568,"Gamma"=144179},"SupportsVariableRefreshRate"=No,"AspectRatio"=15,"MinimumRefreshRate"=50,"WhitePoints"=({"X"=20544,"Y"=21568,"Gamma"=144179}),"PreciseAspectRatio"=115652,"ContinuousFrequencySupport"="None","SupportsStandby"=Yes,"NativeFormatVerticalPixels"=1440}
| | | | "EDID UUID" = "4C2D580F-0000-0000-331C-0104A53C2278"
and you can see that the two monitors produce absolutely identical output – same serial number, same UUID. Samsung needs a slap, or we need a way to anchor monitor ID to physical port – but the port ID is right there in the output, so macOS could tell them apart anyway! So while Samsung shouldn't use duplicate serials, macOS could work around this. Searching for this 810889805 serial number finds several people who apparently have the same one as I do.
I previously had these same monitors connected to a Mac Pro with an RX580, both connected via HDMI, and while they had other issues, they didn't switch sides.