Does std::hash give same result for same input for different complied builds and different machines?
Does std::hash give same result for same input for different complied builds and different machines?
I have some random test parameters which I need to calculate a hash to detect if I ran with same parameters.
I might run the test using binary recompiled at different time or machine.
Also run on different machines?
Even so I want to detect whether the same parameters were used for the run.
Does std::hash
give same result for same input for different complied builds and different machines?
std::hash
e.g.
std::hash<string>{}("TestcaseParamVal0.7Param0.4");
will this always be a unique number.
@Oighea, not all questions need code, and this one in particular doesn't seem like it needs any to be clear and answerable.
– zneak
6 mins ago
Fact is, the original form is poorly formatted and paragraphed. That is why he got reminded.
– Oighea
1 min ago
1 Answer
1
No, std::hash
does not guarantee that the result will be the same across computers, builds, or even executions of the same build on the same computer. Your only guarantee is that during one execution, objects that are equal have the same hash.
std::hash
If you need repeatability between executions and machines, you can't use std::hash
and must roll out your own equivalent.
std::hash
By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.
added example code
– Nelson Pinto
12 mins ago