# Generate multiple temp name in once

**URL:** <https://discourse.julialang.org/t/generate-multiple-temp-name-in-once/132577>\
**Category:** Internals & Design\
**Created:** [September 22, 2025, 4:31pm UTC](https://discourse.julialang.org/t/generate-multiple-temp-name-in-once/132577 "2025-09-22T16:31:05Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![XLin0mu](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/xlin0mu/32/52688_2.png) [@XLin0mu](https://discourse.julialang.org/u/XLin0mu)\
**Post date:** [September 22, 2025, 4:31pm UTC](https://discourse.julialang.org/t/generate-multiple-temp-name-in-once/132577/1 "2025-09-22T16:31:05Z")

</div>

This is a feature request. I’m not sure whether this request suit, but as for my personal needs, this method is convenient.

Expected:

```julia
julia> tempnames(3)
3-element Vector{String}:
 "C:\\Users\\Xlin0\\AppData\\Local\\Temp\\jl_PCTu9WLIx2"
 "C:\\Users\\Xlin0\\AppData\\Local\\Temp\\jl_zS70TUB0d6"
 "C:\\Users\\Xlin0\\AppData\\Local\\Temp\\jl_TalcLuHKLI"

```

Possible implementation:

```julia
function tempnames(amount::Int, parent::AbstractString=tempdir(); max_tries::Int=100, cleanup::Bool=true)
    amount > 0 || throw(ArgumentError("amount should be positive($(repr(amount)))"))
    isdir(parent) || throw(ArgumentError("$(repr(parent)) is not a directory"))

    prefix = joinpath(parent, temp_prefix)
    filenames = Vector{Union{String,Nothing}}(nothing, amount)

    for i in 1:amount
        tried_name = string(prefix, _rand_filename())
        if !ispath(tried_name)
            filenames[i] = tried_name
        end
    end

    for i in 1:max_tries
        inds = findall(isnothing.(filenames))
        if length(inds) > 0
            for j in inds
                tried_name = string(prefix, _rand_filename())
                if !ispath(tried_name)
                    filenames[j] = tried_name
                end
            end
        else
            break
        end
    end

    if in(x -> isnothing(x), filenames)
        error("filenames: max_tries exhausted")
    end

    filenames = Vector{String}(filenames)

    cleanup && temp_cleanup_later(filenames)
    return filenames
end

```

---

<div class="post-metadata">

**Author:** ![PatrickHaecker](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/patrickhaecker/32/222891_2.png) [@PatrickHaecker](https://discourse.julialang.org/u/PatrickHaecker)\
**Post date:** [September 23, 2025, 3:39am UTC](https://discourse.julialang.org/t/generate-multiple-temp-name-in-once/132577/2 "2025-09-23T03:39:38Z")

</div>

Thanks, @XLin0mu, for contributing to improve Julia. This is in general very welcomed.

As you already considered, this is the wrong place to contribute code. Code contribution happens at github. Either for [Julia itself](https://github.com/JuliaLang/julia/) (to end in `Base`) or in a suitable package (I haven’t checked if there are any).

There you’d typically open an issue and describe your problem. This would include describing why for the occasional use `[tempname() for _ in 1:3]` is too inconvenient and why for a frequent use in a single code base defining it yourself with something like `tempnames(n) = [tempname() for _ in 1:n]` is not a good solution.

Then, after there is agreement that the problem should be fixed in the corresponding code base, you’d typically commit a PR (pull request) using `git`. There you’d argue why `tempnames` should be independent of `tempname` (if you want to propose exactly your current implementation) instead of a repeated call to `tempname`.

This is no strict “it always needs to happen exactly like this” thing, but I hope it provides you some guidance.

My personal guess (I am not a Julia maintainer): The bar to add `tempnames` to `Base` is probably too high. If you really need it frequently across several code bases, your best chance in my opinion is to find a suitable package or create a new package.

---

<div class="post-metadata">

**Author:** ![XLin0mu](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/xlin0mu/32/52688_2.png) [@XLin0mu](https://discourse.julialang.org/u/XLin0mu)\
**Post date:** [September 23, 2025, 6:18am UTC](https://discourse.julialang.org/t/generate-multiple-temp-name-in-once/132577/3 "2025-09-23T06:18:00Z")

</div>

Thanks for advising, I’ll go there.

Just in case:  
I created this topic after checking the [contributing-guideline](https://github.com/JuliaLang/julia/blob/master/CONTRIBUTING.md), where I found:

> “Library feature requests are generally not accepted on this issue tracker. New libraries should be developed as [packages](https://julialang.github.io/Pkg.jl/v1/creating-packages/). Discuss ideas for libraries at the [Julia Discourse forum](https://discourse.julialang.org/). Doing so will often lead to pointers to existing projects and bring together collaborators with common interests.”

I actually stopped filling an issue and turn to here because “Library feature” may include Standard Library(and Base) which I thought.

The “Library” there only refering thrid-part packages, is that understanding right?

---

<div class="post-metadata">

**Author:** ![PatrickHaecker](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/patrickhaecker/32/222891_2.png) [@PatrickHaecker](https://discourse.julialang.org/u/PatrickHaecker)\
**Post date:** [September 23, 2025, 1:24pm UTC](https://discourse.julialang.org/t/generate-multiple-temp-name-in-once/132577/4 "2025-09-23T13:24:16Z")

</div>

“Library” or “library feature request” typically mean a bundle of types/macros/methods that belong together. You can look at some of the most starred packages to get a feeling for what is meant.  
They are discussed in discourse, but typically not in the Internals & Design category.

Improvements like a single method or some code lines typically go to Github.

Questions about specific code parts of Julia would fit Internals & Design, but questions about packages should typically be in the General Usage category.

Again: No black and white, only general guidance.

---

<div class="post-metadata">

**Author:** ![Sukera](https://avatars.discourse-cdn.com/v4/letter/s/ce7236/32.png) [@Sukera](https://discourse.julialang.org/u/Sukera)\
**Post date:** [September 23, 2025, 3:28pm UTC](https://discourse.julialang.org/t/generate-multiple-temp-name-in-once/132577/5 "2025-09-23T15:28:35Z")

</div>

Note that julia already provides [`tempname`](https://docs.julialang.org/en/v1/base/file/#Base.Filesystem.tempname), which can be used for this purpose & is cross platform.

Also keep in mind that you may run into [Time-of-check to time-of-use - Wikipedia](https://en.m.wikipedia.org/wiki/Time-of-check_to_time-of-use) if you don’t let the OS already create the files/dirs for you.
