diff options
author | Anton L. Šijanec <anton@sijanec.eu> | 2020-05-01 15:18:12 +0200 |
---|---|---|
committer | Anton L. Šijanec <anton@sijanec.eu> | 2020-05-01 15:18:12 +0200 |
commit | 6961e4237f24306ab2475f4f527a7c802134c4d9 (patch) | |
tree | 0d18e9dd78fe3dee482872a65fbf823e00cd31db /lib/randstring.c | |
parent | folder structure README.mf (diff) | |
download | bverbose-6961e4237f24306ab2475f4f527a7c802134c4d9.tar bverbose-6961e4237f24306ab2475f4f527a7c802134c4d9.tar.gz bverbose-6961e4237f24306ab2475f4f527a7c802134c4d9.tar.bz2 bverbose-6961e4237f24306ab2475f4f527a7c802134c4d9.tar.lz bverbose-6961e4237f24306ab2475f4f527a7c802134c4d9.tar.xz bverbose-6961e4237f24306ab2475f4f527a7c802134c4d9.tar.zst bverbose-6961e4237f24306ab2475f4f527a7c802134c4d9.zip |
Diffstat (limited to '')
-rw-r--r-- | lib/randstring.c | 21 |
1 files changed, 21 insertions, 0 deletions
diff --git a/lib/randstring.c b/lib/randstring.c new file mode 100644 index 0000000..2eeed8f --- /dev/null +++ b/lib/randstring.c @@ -0,0 +1,21 @@ +#pragma once +char *randstring(size_t length) { + + static char charset[] = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789"; + char *randomString = NULL; + + if (length) { + randomString = malloc(sizeof(char) * (length +1)); + + if (randomString) { + for (int n = 0;n < length;n++) { + int key = rand() % (int)(sizeof(charset) -1); + randomString[n] = charset[key]; + } + + randomString[length] = '\0'; + } + } + + return randomString; +} |