blob: 1860a778547cc1e5dfa3b6c87f1a6d08633489d8 (
plain) (
blame)
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
40
41
42
43
44
45
46
47
48
49
|
#include "cmd_rand_libc.h"
void *cmd_rand_libc(void *data)
{
char *ret = NULL;
const int buf_size = 128;
char buf[buf_size+1];
printf("RAND LIBC\n");
int i;
int count;
int rand_val;
sds params;
sds out_result;
sds *tokens;
if (data == NULL)
{
rand_val = rand();
snprintf(buf, buf_size, "%d", rand_val);
} else {
//cut output to 512
char str_integer[16];
unsigned int rand_state;
params = sdsnew(data);
out_result = sdsempty();
tokens = sdssplitargs(params, &count);
for (i=0;i<count;i++)
{
rand_state = atoi(tokens[i]);
snprintf(str_integer, 16, "%d ", rand_r(&rand_state));
out_result = sdscat(out_result, str_integer);
}
out_result = sdscat(out_result,"\n");
snprintf(buf, buf_size, "%s", out_result);
sdsfree(params);
sdsfree(out_result);
sdsfreesplitres(tokens, count);
}
ret = alloc_new_str(buf);
return ret;
}
|