-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtask.c
More file actions
39 lines (37 loc) · 895 Bytes
/
task.c
File metadata and controls
39 lines (37 loc) · 895 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
/*
* Arbitrary fork task
*/
#include "task.h"
/* https://codereview.stackexchange.com/questions/29198/random-string-generator-in-c */
char* form_rand_string(char* str, unsigned int size)
{
const char charset[] = "abcdefghijklmnopqrstuvwxyz";
int charset_size = 25;
int key = 0;
if (size > 0)
{
--size;
for (unsigned int n = 0; n < size; n++)
{
key = rand() % charset_size;
str[n] = charset[key];
}
str[size] = '\0';
}
return str;
}
long hash()
{
long hash = 0;
unsigned int str_size = 10;
char rand_str[str_size];
form_rand_string(rand_str, str_size);
const int a = rand() * 10;
const int m = rand() * 15;
for (unsigned int i = 0; i < str_size; ++i)
{
hash += (long)pow(a, str_size - (i+1)) * rand_str[i];
hash = hash % m;
}
return hash;
}