diff --git a/inc/stdlib.h b/inc/stdlib.h index 0a77862..53c7f75 100644 --- a/inc/stdlib.h +++ b/inc/stdlib.h @@ -33,6 +33,7 @@ void srand(uint32_t seed); int32_t rand(void); +void getrandom(void* buffer, size_t size); static inline int32_t abs(int32_t a) diff --git a/src/stdlib.c b/src/stdlib.c index 66c19a7..f0053e2 100644 --- a/src/stdlib.c +++ b/src/stdlib.c @@ -334,3 +334,19 @@ { return 0xDEADBEEF; } + + +void getrandom(void* buffer, size_t size) +{ + uint8_t* ptr = (uint8_t*)buffer; + + while(size) + { + const size_t xfer_size = size < 4 ? size : 4; + size -= xfer_size; + + const uint32_t r = rand(); + memcpy(ptr, &r, xfer_size); + ptr += xfer_size; + } +}