Skip to content
This repository has been archived by the owner on Sep 3, 2022. It is now read-only.

Commit

Permalink
implement faster random number generation without segfaulting
Browse files Browse the repository at this point in the history
  • Loading branch information
gltile-two-electric-boogaloo committed May 20, 2022
1 parent 4197be3 commit 0f3cfad
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 4 deletions.
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@
[`/dev/uwurandom`](https://github.com/valadaptive/uwurandom) generates data through a tiny catgirl furiously typing away utter nonsense inside your computer.

uwurandom-in-userspace does the same thing without the need to insert a kernel module.

(uwurandom-in-userspace does not use a cryptographically secure random number generator.)
## Installation and usage

### Download uwurandom
Expand Down
9 changes: 5 additions & 4 deletions uwurandom.c
Original file line number Diff line number Diff line change
Expand Up @@ -1310,7 +1310,8 @@ uint64_t rol64(uint64_t x, int k) {
return (x << k) | (x >> (64 - k));
}

uint64_t xoshiro256ss(uint64_t s[4]) {
uint64_t xoshiro256ss(uwu_state *state) {
uint64_t *s = state->rand_state;
uint64_t const result = rol64(s[1] * 5, 7) * 9;
uint64_t const t = s[1] << 17;

Expand All @@ -1328,9 +1329,9 @@ uint64_t xoshiro256ss(uint64_t s[4]) {
static void get_random_buffered(uwu_state *state, void *dst, size_t size) {
// TODO: handle cases where size is more than 8 bytes

if (size > (RAND_SIZE - state->rng_idx)) {
uint64_t rand = xoshiro256ss(state->rand_state);
state->rng_buf = (char*)rand;
if (size < (sizeof(uint64_t) - state->rng_idx)) {
uint64_t rand = xoshiro256ss(state);
*(state->rng_buf) = rand;
state->rng_idx = 0;
}
memcpy(dst, state->rng_buf + state->rng_idx, size);
Expand Down

0 comments on commit 0f3cfad

Please sign in to comment.