> Чего хочу - ну смотри, есть у меня РНР , там могу
> вызвать Random_bytes , srand и т.д.вот тибе похапешный рандом (одоптировано под компеляцию теста)
```
#include <assert.h>
#include <stdio.h>
#include <errno.h>
#include <unistd.h>
#include <fcntl.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <sys/syscall.h>
#define SUCCESS 1
#define FAILURE 0
int php_random_bytes(void *bytes, size_t size) {
size_t read_bytes = 0;
ssize_t n;
/* Linux getrandom(2) syscall or FreeBSD getrandom(2) function*/
/* Keep reading until we get enough entropy */
while (read_bytes < size) {
/* Below, (bytes + read_bytes) is pointer arithmetic.
bytes read_bytes size
| | |
[#######=============] (we're going to write over the = region)
\\\\\\\\\\\\\
amount_to_read
*/
size_t amount_to_read = size - read_bytes;
n = syscall(SYS_getrandom, bytes + read_bytes, amount_to_read, 0);
if (n == -1) {
if (errno == ENOSYS) {
/* This can happen if PHP was compiled against a newer kernel where getrandom()
* is available, but then runs on an older kernel without getrandom(). If this
* happens we simply fall back to reading from /dev/urandom. */
assert(read_bytes == 0);
break;
} else if (errno == EINTR || errno == EAGAIN) {
/* Try again */
continue;
} else {
/* If the syscall fails, fall back to reading from /dev/urandom */
break;
}
}
read_bytes += (size_t) n;
}
if (read_bytes < size) {
int fd;
struct stat st;
if (fd < 0) {
#if HAVE_DEV_URANDOM
fd = open("/dev/urandom", O_RDONLY);
#else
fd = open("/dev/random", O_RDONLY);
#endif
if (fd < 0) {
return FAILURE;
}
/* Does the file exist and is it a character device? */
if (fstat(fd, &st) != 0 ||
# ifdef S_ISNAM
!(S_ISNAM(st.st_mode) || S_ISCHR(st.st_mode))
# else
!S_ISCHR(st.st_mode)
# endif
) {
close(fd);
return FAILURE;
}
}
for (read_bytes = 0; read_bytes < size; read_bytes += (size_t) n) {
n = read(fd, bytes + read_bytes, size - read_bytes);
if (n <= 0) {
break;
}
}
if (read_bytes < size) {
return FAILURE;
}
}
return SUCCESS;
}
int main(void) {
char data[129];
php_random_bytes(&data, 128);
return 0;
}
```
gcc pohape-random.c -o pohapernd
Имино из тваиго похапе, нафига оно тибе ?