1 #ifndef __XTRA_RAND_H__
2 #define __XTRA_RAND_H__
10 #define XTRA_INT_MAX 2147483647
12 #define CHARSET "abcdefghijklmnopqrstuvwxyz"
13 #define CHARSET_LEN 26
17 typedef long double f128;
26 rng(
size_t lb,
size_t ub) {
27 #if defined(__linux__) || defined(__APPLE__)
29 timespec_get(&spec, TIME_UTC);
32 int seed = lb + ((22695477 * ns) % 4294967296) % (ub - lb + 1);
40 unix_rng(
size_t lb,
size_t ub)
42 int fd = open(
"/dev/urandom", O_RDONLY);
49 ssize_t result = read(fd, &random,
sizeof(random));
52 if(result !=
sizeof(random)) {
56 return lb + (random % (ub - lb + 1));
64 return (
int)rng(0, XTRA_INT_MAX-1);
68 randib(
int lb,
int ub) {
69 return (
int)rng(lb, ub);
75 return CHARSET[rng(0, CHARSET_LEN - 1)];
81 char *str = (
char*)malloc(len + 1);
New functions and types related to string and string manipulation.