Question: My application generates loads of images and in order to save memory, I write these files to the temporary directory and read them when needed. I write two versions of the same image to the tmp folder one the thumbnail version at lower resolution and the other is full size. To make the file names unpredictable, I add a string hash at the end.

For instance I want to have two images one called "ThumbnailImage.fgl8bda" and the other "FullImage.fgl8bda"

This is the code I use:

```
NSString *fileName = @"Image.XXXXXXX";
NSString *thumbName = [@"Thumbnail" stringByAppendingFormat:@"%@", fileName];
NSString * thumbPath = [self writeToTempFile:thumbNailImage andName: thumbName];

NSString *fullName = [@"Full" stringByAppendingFormat:@"%@", fileName];
NSString *fullPath = [self writeToTempFile:fullImage andName: fullName];

```

However, the two files come out with different names, i.e. each time I use the fileName variable the hash is regenerated. For instance, my two images are called "ThumbnailImage.jhu078l" and "FullImage.ksi9ert".

Any idea how I can use the same hash more than once?

Answer: 
@KennyTM has a correct solution, but he didn't explain the cause.

writeToTempFile does *not* use a hash to fill in the unique part of the name. Instead, it uses a new unique random string for each call.
@TimG

It doesn't really make a difference. That too ends up in different names.

When I write

```
NSString *fileName = @"Image.XXXXXXX";

```

The `XXXXXXX` part of the fileName is replaced by 7 random characters so that the filenames are not predictable. 

Cheers