Better random (unique) file nameWhat will happen, if I don't specify random seed by SeedRandom function?Generating unique random number listsHow to generate a unique file name similar as that created by CreateTemporaryUse modified part of file path as new file nameHow to return notebook's own file nameWhy doesn't SeedRandom work here?Get (<<) Evaluate File NameRandom phases at each run in a wave superpositionRandom given nameRandom number generation within Compile and Parallelization->TrueMultiple unique random samples?

Implicit conversion between decimals with different precisions

Do grungs have a written language?

How to delete multiple process id of a single process?

How to say "just a precision" properly in English?

Does the Milky Way orbit around anything?

Wearing special clothes in public while in niddah- isn't this a lack of tznius?

Why does this function pointer assignment work when assigned directly but not with the conditional operator?

How to extract values of multiple topics in onMessageArrived(message) function of Paho MQTT JavaScript API?

How to get the speed of my spaceship?

How would a sea turtle end up on its back?

How to play a D major chord lower than the open E major chord on guitar?

Did Stalin kill all Soviet officers involved in the Winter War?

Is conquering your neighbors to fight a greater enemy a valid strategy?

Bringing coumarin-containing liquor into the USA

What is the shape of the upper boundary of water hitting a screen?

How important is it for multiple POVs to run chronologically?

Tiny URL creator

Was the 45.9°C temperature in France in June 2019 the highest ever recorded in France?

What is the maximum amount of diamond in one Minecraft game?

Is there an upper limit on the number of cards a character can declare to draw from the Deck of Many Things?

What is the meaning of "prairie-dog" in this sentence?

Can you take the Dodge action while prone?

How did the IEC decide to create kibibytes?

What do I need to see before Spider-Man: Far From Home?



Better random (unique) file name


What will happen, if I don't specify random seed by SeedRandom function?Generating unique random number listsHow to generate a unique file name similar as that created by CreateTemporaryUse modified part of file path as new file nameHow to return notebook's own file nameWhy doesn't SeedRandom work here?Get (<<) Evaluate File NameRandom phases at each run in a wave superpositionRandom given nameRandom number generation within Compile and Parallelization->TrueMultiple unique random samples?






.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty margin-bottom:0;








2












$begingroup$


In order to avoid conflict with file names produced by some code running in multiple instances of Mathematica I append the date and a random string at the end hoping to create a unique filename.



The date is good enough most of the time but the random integer is there for the (unlikely) event that two files get created in the same second. I create it with:



Random[Integer,10^5]


Now lately I found out this is completely useless, because it seems the multiple instances of Mathematica will use exactly the same data to create a random number creating exactly the same random integer.



What is a simple way to get a better random integer that is not the same when multiple instances of Mathematica run the same code at almost exactly the same time?










share|improve this question











$endgroup$







  • 1




    $begingroup$
    One possibility would be to use SeedRandom (for example, use the time of day to set the seed at the start of the process). Or maybe to create the file names sequentially rather than randomly.
    $endgroup$
    – bill s
    9 hours ago







  • 3




    $begingroup$
    Why not use unique information such as $ProcessID or even better $SessionID ?
    $endgroup$
    – rhermans
    9 hours ago







  • 2




    $begingroup$
    Related: mathematica.stackexchange.com/a/99795/12 I thought recent versions will never start with the same seed, even if they start at the same time. What you describe just should not happen.
    $endgroup$
    – Szabolcs
    9 hours ago











  • $begingroup$
    @Szabolcs, ah that depends on how recent it needs to be. Indeed I should have added the version where I encountered this which is indeed a bit outdated (11.1.1 for Linux x86 (64-bit)).
    $endgroup$
    – Kvothe
    7 hours ago










  • $begingroup$
    @bill, how would I do this? I might need to read the documentation on SeedRandom more clearly but it seems it would not help here. The idea is that the code should produce different output for the same nb (and possibly the same time or very close to it on the system clock), without having to change anything in the .nb, such as the n in SeedRandom manually.
    $endgroup$
    – Kvothe
    7 hours ago

















2












$begingroup$


In order to avoid conflict with file names produced by some code running in multiple instances of Mathematica I append the date and a random string at the end hoping to create a unique filename.



The date is good enough most of the time but the random integer is there for the (unlikely) event that two files get created in the same second. I create it with:



Random[Integer,10^5]


Now lately I found out this is completely useless, because it seems the multiple instances of Mathematica will use exactly the same data to create a random number creating exactly the same random integer.



What is a simple way to get a better random integer that is not the same when multiple instances of Mathematica run the same code at almost exactly the same time?










share|improve this question











$endgroup$







  • 1




    $begingroup$
    One possibility would be to use SeedRandom (for example, use the time of day to set the seed at the start of the process). Or maybe to create the file names sequentially rather than randomly.
    $endgroup$
    – bill s
    9 hours ago







  • 3




    $begingroup$
    Why not use unique information such as $ProcessID or even better $SessionID ?
    $endgroup$
    – rhermans
    9 hours ago







  • 2




    $begingroup$
    Related: mathematica.stackexchange.com/a/99795/12 I thought recent versions will never start with the same seed, even if they start at the same time. What you describe just should not happen.
    $endgroup$
    – Szabolcs
    9 hours ago











  • $begingroup$
    @Szabolcs, ah that depends on how recent it needs to be. Indeed I should have added the version where I encountered this which is indeed a bit outdated (11.1.1 for Linux x86 (64-bit)).
    $endgroup$
    – Kvothe
    7 hours ago










  • $begingroup$
    @bill, how would I do this? I might need to read the documentation on SeedRandom more clearly but it seems it would not help here. The idea is that the code should produce different output for the same nb (and possibly the same time or very close to it on the system clock), without having to change anything in the .nb, such as the n in SeedRandom manually.
    $endgroup$
    – Kvothe
    7 hours ago













2












2








2





$begingroup$


In order to avoid conflict with file names produced by some code running in multiple instances of Mathematica I append the date and a random string at the end hoping to create a unique filename.



The date is good enough most of the time but the random integer is there for the (unlikely) event that two files get created in the same second. I create it with:



Random[Integer,10^5]


Now lately I found out this is completely useless, because it seems the multiple instances of Mathematica will use exactly the same data to create a random number creating exactly the same random integer.



What is a simple way to get a better random integer that is not the same when multiple instances of Mathematica run the same code at almost exactly the same time?










share|improve this question











$endgroup$




In order to avoid conflict with file names produced by some code running in multiple instances of Mathematica I append the date and a random string at the end hoping to create a unique filename.



The date is good enough most of the time but the random integer is there for the (unlikely) event that two files get created in the same second. I create it with:



Random[Integer,10^5]


Now lately I found out this is completely useless, because it seems the multiple instances of Mathematica will use exactly the same data to create a random number creating exactly the same random integer.



What is a simple way to get a better random integer that is not the same when multiple instances of Mathematica run the same code at almost exactly the same time?







random files-and-directories unique






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited 8 hours ago









rhermans

22.3k4 gold badges41 silver badges107 bronze badges




22.3k4 gold badges41 silver badges107 bronze badges










asked 9 hours ago









KvotheKvothe

1,0603 silver badges18 bronze badges




1,0603 silver badges18 bronze badges







  • 1




    $begingroup$
    One possibility would be to use SeedRandom (for example, use the time of day to set the seed at the start of the process). Or maybe to create the file names sequentially rather than randomly.
    $endgroup$
    – bill s
    9 hours ago







  • 3




    $begingroup$
    Why not use unique information such as $ProcessID or even better $SessionID ?
    $endgroup$
    – rhermans
    9 hours ago







  • 2




    $begingroup$
    Related: mathematica.stackexchange.com/a/99795/12 I thought recent versions will never start with the same seed, even if they start at the same time. What you describe just should not happen.
    $endgroup$
    – Szabolcs
    9 hours ago











  • $begingroup$
    @Szabolcs, ah that depends on how recent it needs to be. Indeed I should have added the version where I encountered this which is indeed a bit outdated (11.1.1 for Linux x86 (64-bit)).
    $endgroup$
    – Kvothe
    7 hours ago










  • $begingroup$
    @bill, how would I do this? I might need to read the documentation on SeedRandom more clearly but it seems it would not help here. The idea is that the code should produce different output for the same nb (and possibly the same time or very close to it on the system clock), without having to change anything in the .nb, such as the n in SeedRandom manually.
    $endgroup$
    – Kvothe
    7 hours ago












  • 1




    $begingroup$
    One possibility would be to use SeedRandom (for example, use the time of day to set the seed at the start of the process). Or maybe to create the file names sequentially rather than randomly.
    $endgroup$
    – bill s
    9 hours ago







  • 3




    $begingroup$
    Why not use unique information such as $ProcessID or even better $SessionID ?
    $endgroup$
    – rhermans
    9 hours ago







  • 2




    $begingroup$
    Related: mathematica.stackexchange.com/a/99795/12 I thought recent versions will never start with the same seed, even if they start at the same time. What you describe just should not happen.
    $endgroup$
    – Szabolcs
    9 hours ago











  • $begingroup$
    @Szabolcs, ah that depends on how recent it needs to be. Indeed I should have added the version where I encountered this which is indeed a bit outdated (11.1.1 for Linux x86 (64-bit)).
    $endgroup$
    – Kvothe
    7 hours ago










  • $begingroup$
    @bill, how would I do this? I might need to read the documentation on SeedRandom more clearly but it seems it would not help here. The idea is that the code should produce different output for the same nb (and possibly the same time or very close to it on the system clock), without having to change anything in the .nb, such as the n in SeedRandom manually.
    $endgroup$
    – Kvothe
    7 hours ago







1




1




$begingroup$
One possibility would be to use SeedRandom (for example, use the time of day to set the seed at the start of the process). Or maybe to create the file names sequentially rather than randomly.
$endgroup$
– bill s
9 hours ago





$begingroup$
One possibility would be to use SeedRandom (for example, use the time of day to set the seed at the start of the process). Or maybe to create the file names sequentially rather than randomly.
$endgroup$
– bill s
9 hours ago





3




3




$begingroup$
Why not use unique information such as $ProcessID or even better $SessionID ?
$endgroup$
– rhermans
9 hours ago





$begingroup$
Why not use unique information such as $ProcessID or even better $SessionID ?
$endgroup$
– rhermans
9 hours ago





2




2




$begingroup$
Related: mathematica.stackexchange.com/a/99795/12 I thought recent versions will never start with the same seed, even if they start at the same time. What you describe just should not happen.
$endgroup$
– Szabolcs
9 hours ago





$begingroup$
Related: mathematica.stackexchange.com/a/99795/12 I thought recent versions will never start with the same seed, even if they start at the same time. What you describe just should not happen.
$endgroup$
– Szabolcs
9 hours ago













$begingroup$
@Szabolcs, ah that depends on how recent it needs to be. Indeed I should have added the version where I encountered this which is indeed a bit outdated (11.1.1 for Linux x86 (64-bit)).
$endgroup$
– Kvothe
7 hours ago




$begingroup$
@Szabolcs, ah that depends on how recent it needs to be. Indeed I should have added the version where I encountered this which is indeed a bit outdated (11.1.1 for Linux x86 (64-bit)).
$endgroup$
– Kvothe
7 hours ago












$begingroup$
@bill, how would I do this? I might need to read the documentation on SeedRandom more clearly but it seems it would not help here. The idea is that the code should produce different output for the same nb (and possibly the same time or very close to it on the system clock), without having to change anything in the .nb, such as the n in SeedRandom manually.
$endgroup$
– Kvothe
7 hours ago




$begingroup$
@bill, how would I do this? I might need to read the documentation on SeedRandom more clearly but it seems it would not help here. The idea is that the code should produce different output for the same nb (and possibly the same time or very close to it on the system clock), without having to change anything in the .nb, such as the n in SeedRandom manually.
$endgroup$
– Kvothe
7 hours ago










2 Answers
2






active

oldest

votes


















7












$begingroup$

It might be best to use CreateUUID.





CreateUUID[]



 "73ccc27c-687f-4eca-8214-ceeb8a8b7773"



The Properties & Relations section shows a way to express this string as an integer if that's what you're after:



FromDigits[StringReplace[CreateUUID[], "-" -> ""], 16]



296740835687065620982102887154699649600






share|improve this answer









$endgroup$








  • 1




    $begingroup$
    I don't think this is a very good idea, adding an empty-digit number to a file name. UUIDs have their uses, but this shouldn't be one of them.
    $endgroup$
    – High Performance Mark
    8 hours ago










  • $begingroup$
    In my previous comment I wrote umpty-digit number, which got autocorrected to something meaningless.
    $endgroup$
    – High Performance Mark
    7 hours ago






  • 1




    $begingroup$
    Why do you think it is a bad idea, @HighPerformanceMark?
    $endgroup$
    – user6014
    6 hours ago










  • $begingroup$
    In this case the question seeks a way to disambiguate file names generated by different processes at approximately the same time; about 90% of the digits of the UUID are wasted for this. More generally, UUIDs are a non-human-friendly way of identifying resources. Quickly now, are the following two UUIDs the same ... 7adba397-30fa-45a4-9bd3-6283712a942c, 7adba397-30fa-45a4-9bd3-6283712a942c ?
    $endgroup$
    – High Performance Mark
    5 hours ago


















1












$begingroup$

This should give you a string that are unique. It uses $SessionID and $ProcessID which are a unique combination by definition.



Short name, almost unique.



Hash in "Base36String" to keep the string short (28 characters). It has the date and $KernelID in plain text for easy identification.



StringJoin[
Riffle[

Hash[$SessionID , $ProcessID, "CRC32", "Base36String"],
DateString["Year", "MonthNameShort", "Day", "Hour24", "Minute",
"Second", "MillisecondShort"],
ToString[$KernelID]
, "-"]
]



"02y4q0o-2019Jul04180113431-0"





Long names, absolutely unique



If you can afford extremely long names, you could leave $SessionID and $ProcessID unhashed.



You can shorten the string length also using IntegerString with "Base64" encoding.



StringJoin[
Riffle[
Flatten@
StringDelete[
IntegerString[$SessionID , $ProcessID, "Base64"], "+", "/",
"="],
DateString["Year", "MonthNameShort", "Day", "Hour24", "Minute",
"Second", "MillisecondShort"],
ToString[$KernelID]
, "-"]
]


Otherwise use them to define folder (directory) names.



FileNameJoin[
ToString /@
$MachineName,
$
SessionID ,
$ProcessID,
DateString[
"Year",
"MonthNameShort",
"Day",
"Hour24",
"Minute",
"Second",
"MillisecondShort"
]

]





share|improve this answer











$endgroup$















    Your Answer








    StackExchange.ready(function()
    var channelOptions =
    tags: "".split(" "),
    id: "387"
    ;
    initTagRenderer("".split(" "), "".split(" "), channelOptions);

    StackExchange.using("externalEditor", function()
    // Have to fire editor after snippets, if snippets enabled
    if (StackExchange.settings.snippets.snippetsEnabled)
    StackExchange.using("snippets", function()
    createEditor();
    );

    else
    createEditor();

    );

    function createEditor()
    StackExchange.prepareEditor(
    heartbeatType: 'answer',
    autoActivateHeartbeat: false,
    convertImagesToLinks: false,
    noModals: true,
    showLowRepImageUploadWarning: true,
    reputationToPostImages: null,
    bindNavPrevention: true,
    postfix: "",
    imageUploader:
    brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
    contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
    allowUrls: true
    ,
    onDemand: true,
    discardSelector: ".discard-answer"
    ,immediatelyShowMarkdownHelp:true
    );



    );













    draft saved

    draft discarded


















    StackExchange.ready(
    function ()
    StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fmathematica.stackexchange.com%2fquestions%2f201552%2fbetter-random-unique-file-name%23new-answer', 'question_page');

    );

    Post as a guest















    Required, but never shown

























    2 Answers
    2






    active

    oldest

    votes








    2 Answers
    2






    active

    oldest

    votes









    active

    oldest

    votes






    active

    oldest

    votes









    7












    $begingroup$

    It might be best to use CreateUUID.





    CreateUUID[]



     "73ccc27c-687f-4eca-8214-ceeb8a8b7773"



    The Properties & Relations section shows a way to express this string as an integer if that's what you're after:



    FromDigits[StringReplace[CreateUUID[], "-" -> ""], 16]



    296740835687065620982102887154699649600






    share|improve this answer









    $endgroup$








    • 1




      $begingroup$
      I don't think this is a very good idea, adding an empty-digit number to a file name. UUIDs have their uses, but this shouldn't be one of them.
      $endgroup$
      – High Performance Mark
      8 hours ago










    • $begingroup$
      In my previous comment I wrote umpty-digit number, which got autocorrected to something meaningless.
      $endgroup$
      – High Performance Mark
      7 hours ago






    • 1




      $begingroup$
      Why do you think it is a bad idea, @HighPerformanceMark?
      $endgroup$
      – user6014
      6 hours ago










    • $begingroup$
      In this case the question seeks a way to disambiguate file names generated by different processes at approximately the same time; about 90% of the digits of the UUID are wasted for this. More generally, UUIDs are a non-human-friendly way of identifying resources. Quickly now, are the following two UUIDs the same ... 7adba397-30fa-45a4-9bd3-6283712a942c, 7adba397-30fa-45a4-9bd3-6283712a942c ?
      $endgroup$
      – High Performance Mark
      5 hours ago















    7












    $begingroup$

    It might be best to use CreateUUID.





    CreateUUID[]



     "73ccc27c-687f-4eca-8214-ceeb8a8b7773"



    The Properties & Relations section shows a way to express this string as an integer if that's what you're after:



    FromDigits[StringReplace[CreateUUID[], "-" -> ""], 16]



    296740835687065620982102887154699649600






    share|improve this answer









    $endgroup$








    • 1




      $begingroup$
      I don't think this is a very good idea, adding an empty-digit number to a file name. UUIDs have their uses, but this shouldn't be one of them.
      $endgroup$
      – High Performance Mark
      8 hours ago










    • $begingroup$
      In my previous comment I wrote umpty-digit number, which got autocorrected to something meaningless.
      $endgroup$
      – High Performance Mark
      7 hours ago






    • 1




      $begingroup$
      Why do you think it is a bad idea, @HighPerformanceMark?
      $endgroup$
      – user6014
      6 hours ago










    • $begingroup$
      In this case the question seeks a way to disambiguate file names generated by different processes at approximately the same time; about 90% of the digits of the UUID are wasted for this. More generally, UUIDs are a non-human-friendly way of identifying resources. Quickly now, are the following two UUIDs the same ... 7adba397-30fa-45a4-9bd3-6283712a942c, 7adba397-30fa-45a4-9bd3-6283712a942c ?
      $endgroup$
      – High Performance Mark
      5 hours ago













    7












    7








    7





    $begingroup$

    It might be best to use CreateUUID.





    CreateUUID[]



     "73ccc27c-687f-4eca-8214-ceeb8a8b7773"



    The Properties & Relations section shows a way to express this string as an integer if that's what you're after:



    FromDigits[StringReplace[CreateUUID[], "-" -> ""], 16]



    296740835687065620982102887154699649600






    share|improve this answer









    $endgroup$



    It might be best to use CreateUUID.





    CreateUUID[]



     "73ccc27c-687f-4eca-8214-ceeb8a8b7773"



    The Properties & Relations section shows a way to express this string as an integer if that's what you're after:



    FromDigits[StringReplace[CreateUUID[], "-" -> ""], 16]



    296740835687065620982102887154699649600







    share|improve this answer












    share|improve this answer



    share|improve this answer










    answered 9 hours ago









    Chip HurstChip Hurst

    25k1 gold badge61 silver badges98 bronze badges




    25k1 gold badge61 silver badges98 bronze badges







    • 1




      $begingroup$
      I don't think this is a very good idea, adding an empty-digit number to a file name. UUIDs have their uses, but this shouldn't be one of them.
      $endgroup$
      – High Performance Mark
      8 hours ago










    • $begingroup$
      In my previous comment I wrote umpty-digit number, which got autocorrected to something meaningless.
      $endgroup$
      – High Performance Mark
      7 hours ago






    • 1




      $begingroup$
      Why do you think it is a bad idea, @HighPerformanceMark?
      $endgroup$
      – user6014
      6 hours ago










    • $begingroup$
      In this case the question seeks a way to disambiguate file names generated by different processes at approximately the same time; about 90% of the digits of the UUID are wasted for this. More generally, UUIDs are a non-human-friendly way of identifying resources. Quickly now, are the following two UUIDs the same ... 7adba397-30fa-45a4-9bd3-6283712a942c, 7adba397-30fa-45a4-9bd3-6283712a942c ?
      $endgroup$
      – High Performance Mark
      5 hours ago












    • 1




      $begingroup$
      I don't think this is a very good idea, adding an empty-digit number to a file name. UUIDs have their uses, but this shouldn't be one of them.
      $endgroup$
      – High Performance Mark
      8 hours ago










    • $begingroup$
      In my previous comment I wrote umpty-digit number, which got autocorrected to something meaningless.
      $endgroup$
      – High Performance Mark
      7 hours ago






    • 1




      $begingroup$
      Why do you think it is a bad idea, @HighPerformanceMark?
      $endgroup$
      – user6014
      6 hours ago










    • $begingroup$
      In this case the question seeks a way to disambiguate file names generated by different processes at approximately the same time; about 90% of the digits of the UUID are wasted for this. More generally, UUIDs are a non-human-friendly way of identifying resources. Quickly now, are the following two UUIDs the same ... 7adba397-30fa-45a4-9bd3-6283712a942c, 7adba397-30fa-45a4-9bd3-6283712a942c ?
      $endgroup$
      – High Performance Mark
      5 hours ago







    1




    1




    $begingroup$
    I don't think this is a very good idea, adding an empty-digit number to a file name. UUIDs have their uses, but this shouldn't be one of them.
    $endgroup$
    – High Performance Mark
    8 hours ago




    $begingroup$
    I don't think this is a very good idea, adding an empty-digit number to a file name. UUIDs have their uses, but this shouldn't be one of them.
    $endgroup$
    – High Performance Mark
    8 hours ago












    $begingroup$
    In my previous comment I wrote umpty-digit number, which got autocorrected to something meaningless.
    $endgroup$
    – High Performance Mark
    7 hours ago




    $begingroup$
    In my previous comment I wrote umpty-digit number, which got autocorrected to something meaningless.
    $endgroup$
    – High Performance Mark
    7 hours ago




    1




    1




    $begingroup$
    Why do you think it is a bad idea, @HighPerformanceMark?
    $endgroup$
    – user6014
    6 hours ago




    $begingroup$
    Why do you think it is a bad idea, @HighPerformanceMark?
    $endgroup$
    – user6014
    6 hours ago












    $begingroup$
    In this case the question seeks a way to disambiguate file names generated by different processes at approximately the same time; about 90% of the digits of the UUID are wasted for this. More generally, UUIDs are a non-human-friendly way of identifying resources. Quickly now, are the following two UUIDs the same ... 7adba397-30fa-45a4-9bd3-6283712a942c, 7adba397-30fa-45a4-9bd3-6283712a942c ?
    $endgroup$
    – High Performance Mark
    5 hours ago




    $begingroup$
    In this case the question seeks a way to disambiguate file names generated by different processes at approximately the same time; about 90% of the digits of the UUID are wasted for this. More generally, UUIDs are a non-human-friendly way of identifying resources. Quickly now, are the following two UUIDs the same ... 7adba397-30fa-45a4-9bd3-6283712a942c, 7adba397-30fa-45a4-9bd3-6283712a942c ?
    $endgroup$
    – High Performance Mark
    5 hours ago













    1












    $begingroup$

    This should give you a string that are unique. It uses $SessionID and $ProcessID which are a unique combination by definition.



    Short name, almost unique.



    Hash in "Base36String" to keep the string short (28 characters). It has the date and $KernelID in plain text for easy identification.



    StringJoin[
    Riffle[

    Hash[$SessionID , $ProcessID, "CRC32", "Base36String"],
    DateString["Year", "MonthNameShort", "Day", "Hour24", "Minute",
    "Second", "MillisecondShort"],
    ToString[$KernelID]
    , "-"]
    ]



    "02y4q0o-2019Jul04180113431-0"





    Long names, absolutely unique



    If you can afford extremely long names, you could leave $SessionID and $ProcessID unhashed.



    You can shorten the string length also using IntegerString with "Base64" encoding.



    StringJoin[
    Riffle[
    Flatten@
    StringDelete[
    IntegerString[$SessionID , $ProcessID, "Base64"], "+", "/",
    "="],
    DateString["Year", "MonthNameShort", "Day", "Hour24", "Minute",
    "Second", "MillisecondShort"],
    ToString[$KernelID]
    , "-"]
    ]


    Otherwise use them to define folder (directory) names.



    FileNameJoin[
    ToString /@
    $MachineName,
    $
    SessionID ,
    $ProcessID,
    DateString[
    "Year",
    "MonthNameShort",
    "Day",
    "Hour24",
    "Minute",
    "Second",
    "MillisecondShort"
    ]

    ]





    share|improve this answer











    $endgroup$

















      1












      $begingroup$

      This should give you a string that are unique. It uses $SessionID and $ProcessID which are a unique combination by definition.



      Short name, almost unique.



      Hash in "Base36String" to keep the string short (28 characters). It has the date and $KernelID in plain text for easy identification.



      StringJoin[
      Riffle[

      Hash[$SessionID , $ProcessID, "CRC32", "Base36String"],
      DateString["Year", "MonthNameShort", "Day", "Hour24", "Minute",
      "Second", "MillisecondShort"],
      ToString[$KernelID]
      , "-"]
      ]



      "02y4q0o-2019Jul04180113431-0"





      Long names, absolutely unique



      If you can afford extremely long names, you could leave $SessionID and $ProcessID unhashed.



      You can shorten the string length also using IntegerString with "Base64" encoding.



      StringJoin[
      Riffle[
      Flatten@
      StringDelete[
      IntegerString[$SessionID , $ProcessID, "Base64"], "+", "/",
      "="],
      DateString["Year", "MonthNameShort", "Day", "Hour24", "Minute",
      "Second", "MillisecondShort"],
      ToString[$KernelID]
      , "-"]
      ]


      Otherwise use them to define folder (directory) names.



      FileNameJoin[
      ToString /@
      $MachineName,
      $
      SessionID ,
      $ProcessID,
      DateString[
      "Year",
      "MonthNameShort",
      "Day",
      "Hour24",
      "Minute",
      "Second",
      "MillisecondShort"
      ]

      ]





      share|improve this answer











      $endgroup$















        1












        1








        1





        $begingroup$

        This should give you a string that are unique. It uses $SessionID and $ProcessID which are a unique combination by definition.



        Short name, almost unique.



        Hash in "Base36String" to keep the string short (28 characters). It has the date and $KernelID in plain text for easy identification.



        StringJoin[
        Riffle[

        Hash[$SessionID , $ProcessID, "CRC32", "Base36String"],
        DateString["Year", "MonthNameShort", "Day", "Hour24", "Minute",
        "Second", "MillisecondShort"],
        ToString[$KernelID]
        , "-"]
        ]



        "02y4q0o-2019Jul04180113431-0"





        Long names, absolutely unique



        If you can afford extremely long names, you could leave $SessionID and $ProcessID unhashed.



        You can shorten the string length also using IntegerString with "Base64" encoding.



        StringJoin[
        Riffle[
        Flatten@
        StringDelete[
        IntegerString[$SessionID , $ProcessID, "Base64"], "+", "/",
        "="],
        DateString["Year", "MonthNameShort", "Day", "Hour24", "Minute",
        "Second", "MillisecondShort"],
        ToString[$KernelID]
        , "-"]
        ]


        Otherwise use them to define folder (directory) names.



        FileNameJoin[
        ToString /@
        $MachineName,
        $
        SessionID ,
        $ProcessID,
        DateString[
        "Year",
        "MonthNameShort",
        "Day",
        "Hour24",
        "Minute",
        "Second",
        "MillisecondShort"
        ]

        ]





        share|improve this answer











        $endgroup$



        This should give you a string that are unique. It uses $SessionID and $ProcessID which are a unique combination by definition.



        Short name, almost unique.



        Hash in "Base36String" to keep the string short (28 characters). It has the date and $KernelID in plain text for easy identification.



        StringJoin[
        Riffle[

        Hash[$SessionID , $ProcessID, "CRC32", "Base36String"],
        DateString["Year", "MonthNameShort", "Day", "Hour24", "Minute",
        "Second", "MillisecondShort"],
        ToString[$KernelID]
        , "-"]
        ]



        "02y4q0o-2019Jul04180113431-0"





        Long names, absolutely unique



        If you can afford extremely long names, you could leave $SessionID and $ProcessID unhashed.



        You can shorten the string length also using IntegerString with "Base64" encoding.



        StringJoin[
        Riffle[
        Flatten@
        StringDelete[
        IntegerString[$SessionID , $ProcessID, "Base64"], "+", "/",
        "="],
        DateString["Year", "MonthNameShort", "Day", "Hour24", "Minute",
        "Second", "MillisecondShort"],
        ToString[$KernelID]
        , "-"]
        ]


        Otherwise use them to define folder (directory) names.



        FileNameJoin[
        ToString /@
        $MachineName,
        $
        SessionID ,
        $ProcessID,
        DateString[
        "Year",
        "MonthNameShort",
        "Day",
        "Hour24",
        "Minute",
        "Second",
        "MillisecondShort"
        ]

        ]






        share|improve this answer














        share|improve this answer



        share|improve this answer








        edited 6 hours ago

























        answered 7 hours ago









        rhermansrhermans

        22.3k4 gold badges41 silver badges107 bronze badges




        22.3k4 gold badges41 silver badges107 bronze badges



























            draft saved

            draft discarded
















































            Thanks for contributing an answer to Mathematica Stack Exchange!


            • Please be sure to answer the question. Provide details and share your research!

            But avoid


            • Asking for help, clarification, or responding to other answers.

            • Making statements based on opinion; back them up with references or personal experience.

            Use MathJax to format equations. MathJax reference.


            To learn more, see our tips on writing great answers.




            draft saved


            draft discarded














            StackExchange.ready(
            function ()
            StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fmathematica.stackexchange.com%2fquestions%2f201552%2fbetter-random-unique-file-name%23new-answer', 'question_page');

            );

            Post as a guest















            Required, but never shown





















































            Required, but never shown














            Required, but never shown












            Required, but never shown







            Required, but never shown

































            Required, but never shown














            Required, but never shown












            Required, but never shown







            Required, but never shown







            Popular posts from this blog

            Invision Community Contents History See also References External links Navigation menuProprietaryinvisioncommunity.comIPS Community ForumsIPS Community Forumsthis blog entry"License Changes, IP.Board 3.4, and the Future""Interview -- Matt Mecham of Ibforums""CEO Invision Power Board, Matt Mecham Is a Liar, Thief!"IPB License Explanation 1.3, 1.3.1, 2.0, and 2.1ArchivedSecurity Fixes, Updates And Enhancements For IPB 1.3.1Archived"New Demo Accounts - Invision Power Services"the original"New Default Skin"the original"Invision Power Board 3.0.0 and Applications Released"the original"Archived copy"the original"Perpetual licenses being done away with""Release Notes - Invision Power Services""Introducing: IPS Community Suite 4!"Invision Community Release Notes

            Canceling a color specificationRandomly assigning color to Graphics3D objects?Default color for Filling in Mathematica 9Coloring specific elements of sets with a prime modified order in an array plotHow to pick a color differing significantly from the colors already in a given color list?Detection of the text colorColor numbers based on their valueCan color schemes for use with ColorData include opacity specification?My dynamic color schemes

            Ласкавець круглолистий Зміст Опис | Поширення | Галерея | Примітки | Посилання | Навігаційне меню58171138361-22960890446Bupleurum rotundifoliumEuro+Med PlantbasePlants of the World Online — Kew ScienceGermplasm Resources Information Network (GRIN)Ласкавецькн. VI : Літери Ком — Левиправивши або дописавши її