# Tempfile.new -\> result not unique

**URL:** <https://www.ruby-forum.com/t/tempfile-new-result-not-unique/107164>\
**Category:** Rails\
**Created:** [June 18, 2007, 6:52pm UTC](https://www.ruby-forum.com/t/tempfile-new-result-not-unique/107164 "2007-06-18T18:52:39Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![redgar](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/r/c0e974/32.png) [@redgar](https://www.ruby-forum.com/u/redgar)\
**Post date:** [June 18, 2007, 6:52pm UTC](https://www.ruby-forum.com/t/tempfile-new-result-not-unique/107164/1 "2007-06-18T18:52:39Z")

</div>

Hi,

I am using Tempfile to store temporary data on disk.

The documentation I’ve read (The Ruby Way, p353) states:

“The new method (Tempfile.new(“seed\_str”)) takes a basename as a seed  
string, and concatenates onto it the process id and a unique  
sequence number.”

however, I am testing my web app, and request after request, I end up  
with the exact same filename…

I worked around this by actually adding a random number within the  
seed string:

rand\_str = rand  
Tempfile.new(txt#{rand\_str})

however, I am sure there must be a way to get Tempfile to work  
properly  
and return an actual unique name?

thanks for your help,

\_\_  
Andrea
