87a5965718
FossilOrigin-Name: 01e23fb60d44e99ac685ef618e7d837876f12f6fbc6977c3efbc3c1adb4de2da
26 lines
550 B
C
26 lines
550 B
C
/*---------------------------------------------------------------------
|
|
Random Number Generator
|
|
---------------------------------------------------------------------*/
|
|
|
|
void io_random() {
|
|
int64_t r = 0;
|
|
char buffer[8];
|
|
int i;
|
|
int fd = open("/dev/urandom", O_RDONLY);
|
|
read(fd, buffer, 8);
|
|
close(fd);
|
|
for(i = 0; i < 8; ++i) {
|
|
r = r << 8;
|
|
r += ((int64_t)buffer[i] & 0xFF);
|
|
}
|
|
#ifndef BIT64
|
|
stack_push((CELL)abs((CELL)r));
|
|
#else
|
|
stack_push(llabs(r));
|
|
#endif
|
|
}
|
|
|
|
void io_random_query() {
|
|
stack_push(0);
|
|
stack_push(10);
|
|
}
|