about summary refs log tree commit diff stats
path: root/src/xmpp/jid.c
diff options
context:
space:
mode:
authorMichael Vetter <jubalh@iodoru.org>2019-10-16 10:39:35 +0200
committerMichael Vetter <jubalh@iodoru.org>2019-10-16 10:39:35 +0200
commitf9eb302a5965312713a1bd388904a26e7dadadb0 (patch)
tree81e3a021a0f5a998e6bba22a28e0acd08a445d2d /src/xmpp/jid.c
parent1e09a055ca2ac7b8738d7ade2b8f656682e2c24d (diff)
downloadprofani-tty-f9eb302a5965312713a1bd388904a26e7dadadb0.tar.gz
Move code from jid_random_resource() into own function
Move the code that creates a random string into it's own function
+get_random_string().
Diffstat (limited to 'src/xmpp/jid.c')
-rw-r--r--src/xmpp/jid.c16
1 files changed, 4 insertions, 12 deletions
diff --git a/src/xmpp/jid.c b/src/xmpp/jid.c
index 49bf7b9c..25067050 100644
--- a/src/xmpp/jid.c
+++ b/src/xmpp/jid.c
@@ -198,18 +198,10 @@ jid_fulljid_or_barejid(Jid *jid)
 char*
 jid_random_resource(void)
 {
-    GRand *prng;
-    char rand[5];
-    char alphabet[] = "0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ";
+    char *rand = get_random_string(4);
 
-    prng = g_rand_new();
+    gchar *result = g_strdup_printf("profanity.%s", rand);
+    free(rand);
 
-    int i;
-    for (i = 0; i < 4; i++) {
-        rand[i] = alphabet[g_rand_int_range(prng, 0, sizeof(alphabet))];
-    }
-    rand[4] = '\0';
-    g_rand_free(prng);
-
-    return g_strdup_printf("profanity.%s", rand);
+    return result;
 }