Good way to generate an int from a string
Posted: Thu Feb 08, 2007 12:42 pm
I have some code that runs a program and generates an output image that is dependent on a number of parameters. I am currently attaching a random number to the filename of each image, but what I would like to do is combine all the parameters into one long string and use that string to generate a the number. That way, if a user chooses parameters that they've already used, I can use file_exists to check and see if the image has already been produced.
Right now I am using the function crc32, but the fact that the generated number is sometimes negative just sorta bugs me. I could take the absolute value, but then I run the risk (albeit miniscule) of having crc(string1) = x and crc(string2) = -x, which would incorrectly imply that string1=string2.
Besides, I'm sure there is a better and faster way to do this than using crc32.
Thanks!
Right now I am using the function crc32, but the fact that the generated number is sometimes negative just sorta bugs me. I could take the absolute value, but then I run the risk (albeit miniscule) of having crc(string1) = x and crc(string2) = -x, which would incorrectly imply that string1=string2.
Besides, I'm sure there is a better and faster way to do this than using crc32.
Thanks!