Let me suggest a minimalist generator of pseudorandom numbers. It is based on the structure with nonlinear feedback. I haven't seen this structure before.
- Simple and efficient in hardware or software
- Strongly nonlinear
- Scalable to arbitrary number of states
- No short loops
- No special state initialization procedure
- Passes Diehard battery of tests with state as small as 3 bytes
- Generates one byte at time
- The structure could be extended both in depth and width
///------------------------------- // (c) Vladimir L. Vassilevsky, July 21, 2013 // snipped-for-privacy@abvolt.com // All rights reserved //--------------------------------- //
// Any number of state bytes (more then 2 to pass Diehard test) const u32 number_of_states = 3;
u8 state[number_of_states]; // Initialize state to whatever anything u8 cntr = 0;
const u8 s_box[256]; // This is nonlinear S-box. // You can use S-box from AES or define your own. // Initialization with AES values is omitted for // clarity; one could find it in the // internet.
// Generate random byte
u8 vrnd() { u8 x = cntr++;
u8 tmp_state = state[0] + x; x ^= s_box[state[0]];
for(u32 ci = 1; ci < number_of_states; ci++) // Iteration { state[ci-1] = state[ci] + x; x ^= s_box[state[ci]]; }
state[number_of_states - 1] = tmp_state;
return x; }
This is it. Feedback is welcome.
Vladimir Vassilevsky DSP and Mixed Signal Designs