Unique symlink name inside /tmp#21
Open
zkwinkle wants to merge 1 commit into
Open
Conversation
Owner
|
Sorry, I haven't had time to properly review this. I will probably implement this later using a |
Author
|
That's okay, but I urge you to reconsider my method because it's self contained, and doesn't create any unnecessary files in the system. Right now, |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
This PR addressed #20.
The method to generate the random ID's is to transform the $USER variable into a numerical seed and then use awk
srand(seed)andrand()to generate the 7 character long ID.The solution is a little bit over-engineered I think, but it works perfectly!
I will explain my reasoning but feel free to change anything.
Rationale
I put the procedure inside a
gen_id()function only for the reason that I thought it was orderly.Didn't want to add any dependencies so that's why I went with the current approach. The hashing commands I found depnded on Perl, and even the
$RANDOMvariable apparently wasn't POSIX compliant. That's why I ended up usingawkfor the RNG.The reason the string is decoded into ASCII values is because the seed must be numerical, if you try to pass a string rand() will always return the same values.
The
SEED=$((SEED % 4294967295))is there becausesrand()takes in anunsigned intand 4294967295 is the max value of one.The while loop where I'm checking
while [ ${#ID} -lt $WIDTH ]is there because even if I multipliedrand()by a large enough number, I think there's always a chance it returns really low numbers so this while loop guarantees that ID will reach at least 7 characters long. Could've also added padding to the string but I think to keep generating more random numbers generates more unique numbers than adding padding does?The reason I multiply
rand()*32768in specific is simply because that's what they multiply it by in the shellcheck example for RNG. I think it could be literally any number and it wouldn't matter anyways.Shellcheck
I made sure the commit didn't add any shellcheck warnings or anything, this is my
shellcheckoutput: