mirror of
https://github.com/lakinduakash/linux-wifi-hotspot.git
synced 2024-11-21 19:40:11 +00:00
Add random string generator function
This commit is contained in:
parent
e0777ff70c
commit
b19924c6c9
@ -3,6 +3,8 @@
|
||||
//
|
||||
|
||||
#include <string.h>
|
||||
#include <stdlib.h>
|
||||
#include <time.h>
|
||||
#include "util.h"
|
||||
|
||||
int find_str(char *find, const char **array, int length) {
|
||||
@ -18,3 +20,16 @@ int find_str(char *find, const char **array, int length) {
|
||||
return -1;
|
||||
|
||||
}
|
||||
|
||||
|
||||
void rand_str(char *dest, size_t length) {
|
||||
char charset[] = "0123456789"
|
||||
"abcdefghijklmnopqrstuvwxyz"
|
||||
"ABCDEFGHIJKLMNOPQRSTUVWXYZ";
|
||||
|
||||
while (length-- > 0) {
|
||||
size_t index = (size_t) ((double) rand() / RAND_MAX * (sizeof charset - 1));
|
||||
*dest++ = charset[index];
|
||||
}
|
||||
*dest = '\0';
|
||||
}
|
||||
|
@ -6,5 +6,6 @@
|
||||
#define WIHOTSPOT_UTIL_H
|
||||
|
||||
int find_str(char *find, const char **array, int length);
|
||||
void rand_str(char *dest, size_t length);
|
||||
|
||||
#endif //WIHOTSPOT_UTIL_H
|
||||
|
Loading…
Reference in New Issue
Block a user