New implementation

Be concise.

Be useful.

All contributions dictatorially edited by webmasters to match personal tastes.

Please do not paste any copyright violating resource.

Please try to avoid dependencies to third-party libraries and frameworks.

Other implementations
using System.IO;
string newDir = Path.GetTempPath() + Guid.NewGuid();
Directory.CreateDirectory(newDir);
string mkTmpDir()
{
    import std.uuid, std.file, std.path;
    string d = buildPath(tempDir, randomUUID.toString);
    if (!d.exists)
    {
        mkdir(d);
        return d;
    }
    else return null;
}

string s;
while (!s.length)
  s = mkTmpDir;
import "io/ioutil"
dir, err := ioutil.TempDir("", "")
import System.IO.Temp
withTempDirectory $ \d -> do
  -- do something with d
function createTempDir(): ?string
{
    $separator = DIRECTORY_SEPARATOR;
    $path = rtrim(sys_get_temp_dir(), $separator) . $separator . mt_rand() . microtime(true);
    $createdTempDir = mkdir($path);
    if ($createdTempDir) {
        return $path;
    }

    return null;
}
sysutils
var
  GUID: TGUID;
  Succes: Boolean;

begin
  CreateGUID(GUID);
  Succes := CreateDir(GetTempDir + GUIDToString(GUID));
end.
use Path::Tiny qw(tempdir);
my $path = tempdir;
import tempfile	
td = tempfile.TemporaryDirectory()
require 'tmpdir' 
td = Dir.mktmpdir
extern crate tempdir;
use tempdir::TempDir;
let tmp = TempDir::new("prefix")?;