1
0
mirror of https://github.com/mariadb-corporation/mariadb-connector-c.git synced 2025-08-08 14:02:17 +03:00

Simplify rand_str()function

This commit is contained in:
Vladislav Vaintroub
2016-09-10 13:21:02 +00:00
parent 12797530d5
commit 4ed1ca0c68

View File

@@ -26,8 +26,7 @@ char *rand_str(size_t length) {
char *dest= (char *)malloc(length+1); char *dest= (char *)malloc(length+1);
char *p= dest; char *p= dest;
while (length-- > 0) { while (length-- > 0) {
size_t index = (size_t)((double)rand() / RAND_MAX * (sizeof charset - 1)); *dest++ = charset[rand() % sizeof(charset)];
*dest++ = charset[index];
} }
*dest = '\0'; *dest = '\0';
return p; return p;