How to obtain (almost) unique system identifier in a cross platform way?

后端 未结 4 725
一向
一向 2020-12-07 15:56

I\'m looking for a way to get a number which will almost surely change when running the code on different machines and almost surely stay the same between two runs on the sa

4条回答
  •  感动是毒
    2020-12-07 16:41

    One quite portable solution would be to use modification time of a current executable. stat function is available on unix and windows, although API is different so you would need to use some IFDEFs.

    A binary is unlikely to be deployed at the exactly same time to different machines, so the ids should be unique. The drawback is that the binary update will change the ids.

提交回复
热议问题