I have a string which identifies a customer. On my website, I have 3 different images for customers who have not set a profile picture. I want to randomly associate one of these images to a customer, but not have the image change between sessions.
Is there any problems with using GetHashCode, like in the following code?
switch (CustomerIdString.GetHashCode() % 3)
{
case 0:
return "NoProfileImage0.png";
break;
case 1:
return "NoProfileImage1.png";
break;
case 2:
default:
return "NoProfileImage2.png";
break;
}
I understand there are other solutions, such as-
- Use a better hashing library
- Use the customer id as the seed in a random number generator
- Persist the image name against the customer record
but I like the simplicity (no added libraries, no DB code) of using GetHashCode().