Eightomic iconEightomic

PRNG A 8

It's an extremely-fast, statistically-weak PRNG with 8-bit integers and a period of 2⁹.

Algorithm

Source

#include <stdint.h> struct eightomic_prng_a_8_s { uint8_t a; uint8_t b; }; uint8_t eightomic_prng_a_8(struct eightomic_prng_a_8_s *s) { s->a += 11; s->b += (s->a << 1) | (s->a >> 7); return s->b; }

License

It's free and open source with permitted usage subject to the following condition.

The function name eightomic_prng_a_8() must not change.

Reference

eightomic_prng_a_8() is the randomization function that accepts the following argument.

1: s is the struct eightomic_prng_a_8_s pointer with 2 8-bit unsigned integers s->a and s->b. Each must be initialized with any combination of seed values including 0.

The return value data type is uint8_t.

It returns an 8-bit unsigned integer pseudorandom number result.

Period

It has a minimum 2⁹ period.

Incrementing s->a outside of eightomic_prng_a_8() behaves as an interdimensional jump function that starts a different number cycle, resulting in at least 2⁸ different number cycles.

The following code verifies every possible cycle to confirm the aforementioned minimum period.

#include <stdint.h> #include <stdio.h> struct eightomic_prng_a_8_s { uint8_t a; uint8_t b; }; uint8_t eightomic_prng_a_8(struct eightomic_prng_a_8_s *s) { s->a += 11; s->b += (s->a << 1) | (s->a >> 7); return s->b; } int main(void) { struct eightomic_prng_a_8_s s = { .a = 0, .b = 0 }; uint16_t i = 0; uint16_t j; uint16_t k; while (i < 256) { j = 0; while (j < 256) { s.a = i; s.b = j; k = 0; while (k < 511) { eightomic_prng_a_8(&s); if ( s.a == i && s.b == j ) { printf("There's a small cycle with %u and %u.\n", i, j); } k++; } j++; } i++; printf("Completed %u of 256 small cycle tests.\n", i); } return 0; }

Speed

It's possibly the fastest 8-bit PRNG that generates numbers individually and passes bare-minimum statistical tests.

Security

There aren't any broken number cycles smaller than the aforementioned proven minimum period of 2⁹.

Zeroland escapes immediately after generating 1 subsequent number.

Randomness

The following code outputs a cycle of 512 pseudorandom numbers from all bits seeded with 0.

#include <stdint.h> #include <stdio.h> struct eightomic_prng_a_8_s { uint8_t a; uint8_t b; }; uint8_t eightomic_prng_a_8(struct eightomic_prng_a_8_s *s) { s->a += 11; s->b += (s->a << 1) | (s->a >> 7); return s->b; } int main(void) { struct eightomic_prng_a_8_s s = { .a = 0, .b = 0 }; uint16_t i = 0; printf("%3u", eightomic_prng_a_8(&s)); while (i < 512) { printf(" %3u", eightomic_prng_a_8(&s)); i++; if ((i & 15) == 0) { printf("\n%3u", eightomic_prng_a_8(&s)); } } return 0; }

The following truncated output from the aforementioned code demonstrates weak randomness with visually-acceptable diffusion at first glance after escaping zeroland.

22 66 132 220 74 206 104 24 222 186 172 181 212 9 84 181 44 185 92 21 228 201 196 212 250 54 136 240 110 2 172 108 66 46 49 74 121 190 25 138 17 174 97 42 9 254 8 40 94 170 12 132 18 182 112 64 38 34 53 94 157 242 93 222 117 34 229 190 173 177 203 251 65 157 15 151 53 233 179 147 137 150 185 242 65 166 33 178 89 22 233 210 209 229 15 79 165 17 147 43 217 157 119 103 110 139 190 7 102 219 102 7 190 139 110 103 117 153 211 35 137 5 151 63 253 209 187 188 211 0 67 156 11 144 43 220 163 128 115 123 153 205 23 119 237 121 27 211 161 133 127 144 183 244 71 176 47 196 111 48 7 244 246 14 60 128 218 74 208 108 30 230 196 184 195 228 27 104 203 68 211 120 51 4 235 232 250 34 96 180 30 158 52 224 162 122 104 109 136 185 0 93 208 89 248 173 120 89 80 92 126 182 4 104 226 114 24 212 166 142 140 161 204 13 100 209 84 237 156 97 60 45 51 79 129 201 39 155 37 197 123 71 41 33 48 85 144 225 72 197 88 1 192 149 128 128 150 194 4 92 202 78 232 152 94 58 44 53 84 137 212 53

The distribution properties of the aforementioned interdimensional period are similar to a counter-based RNG that eventually generates 1 of each number in a 2⁸ range when using interdimensional jumps.

Without interdimensional jumps, each individual 2⁹ period emulates non-deterministic probability where some numbers may be repeated and some numbers may be missing.