UltraGrid
UltraGrid Low-Latency High-Resolution Transmission System
Loading...
Searching...
No Matches
random.c File Reference
#include "config.h"
#include "config_win32.h"
#include "config_unix.h"
#include "crypto/random.h"
Include dependency graph for random.c:

Go to the source code of this file.

Functions

uint32_t lbl_random (void)
 
void lbl_srandom (uint32_t seed)
 

Variables

static uint32_t randseed = 1
 

Function Documentation

◆ lbl_random()

uint32_t lbl_random ( void )

Definition at line 61 of file random.c.

62{
63#ifdef HAVE_DEV_URANDOM
64 int fd, res, l;
65
66 fd = open("/dev/urandom", O_RDONLY);
67 if (fd == -1) {
68 perror("Cannot open random sequence generator");
69 abort();
70 }
71 l = read(fd, &res, sizeof(res));
72 if (l != sizeof(res)) {
73 perror("Cannot read random data");
74 abort();
75 }
76 close(fd);
77 return res;
78#else
79 register uint32_t x = randseed;
80 register uint32_t hi, lo, t;
81
82 hi = x / 127773;
83 lo = x % 127773;
84 t = 16807 * lo - 2836 * hi;
85 if (t <= 0)
86 t += 0x7fffffff;
87 randseed = t;
88 return (t);
89#endif
90}
static uint32_t randseed
Definition random.c:54

References randseed.

Referenced by qfDES_generate().

◆ lbl_srandom()

void lbl_srandom ( uint32_t seed)

Definition at line 56 of file random.c.

57{
58 randseed = seed;
59}

References randseed.

Referenced by qfDES_generate().

Variable Documentation

◆ randseed

uint32_t randseed = 1
static

Definition at line 54 of file random.c.

Referenced by lbl_random(), and lbl_srandom().