[Krafton Jungle] PintOS 2.0.0
크래프톤 정글 PintOS
 
Loading...
Searching...
No Matches
random.c File Reference
#include "random.h"
#include <stdbool.h>
#include <stdint.h>
#include "debug.h"
Include dependency graph for random.c:

Functions

static void swap_byte (uint8_t *a, uint8_t *b)
 
void random_init (unsigned seed)
 
void random_bytes (void *buf_, size_t size)
 
unsigned long random_ulong (void)
 

Variables

static uint8_t s [256]
 
static uint8_t s_i
 
static uint8_t s_j
 
static bool inited
 

Function Documentation

◆ random_bytes()

void random_bytes ( void *  buf_,
size_t  size 
)
51 {
52 uint8_t *buf;
53
54 if (!inited)
55 random_init (0);
56
57 for (buf = buf_; size-- > 0; buf++) {
58 uint8_t s_k;
59
60 s_i++;
61 s_j += s[s_i];
62 swap_byte (s + s_i, s + s_j);
63
64 s_k = s[s_i] + s[s_j];
65 *buf = s[s_k];
66 }
67}
uint16_t size
Definition: mmu.h:0
static uint8_t s_j
Definition: random.c:18
static uint8_t s_i
Definition: random.c:18
static bool inited
Definition: random.c:21
static void swap_byte(uint8_t *a, uint8_t *b)
Definition: random.c:25
void random_init(unsigned seed)
Definition: random.c:33
static uint8_t s[256]
Definition: random.c:17
unsigned char uint8_t
Definition: stdint.h:20
Here is the call graph for this function:
Here is the caller graph for this function:

◆ random_init()

void random_init ( unsigned  seed)
33 {
34 uint8_t *seedp = (uint8_t *) &seed;
35 int i;
36 uint8_t j;
37
38 for (i = 0; i < 256; i++)
39 s[i] = i;
40 for (i = j = 0; i < 256; i++) {
41 j += s[i] + seedp[i % sizeof seed];
42 swap_byte (s + i, s + j);
43 }
44
45 s_i = s_j = 0;
46 inited = true;
47}
Here is the call graph for this function:
Here is the caller graph for this function:

◆ random_ulong()

unsigned long random_ulong ( void  )
73 {
74 unsigned long ul;
75 random_bytes (&ul, sizeof ul);
76 return ul;
77}
void random_bytes(void *buf_, size_t size)
Definition: random.c:51
Here is the call graph for this function:

◆ swap_byte()

static void swap_byte ( uint8_t a,
uint8_t b 
)
inlinestatic
25 {
26 uint8_t t = *a;
27 *a = *b;
28 *b = t;
29}
Here is the caller graph for this function:

Variable Documentation

◆ inited

bool inited
static

◆ s

uint8_t s[256]
static

◆ s_i

uint8_t s_i
static

◆ s_j

uint8_t s_j
static