14
frogstair
68d

I made a pseudo random number generator in assembly. Feels pretty cool

Comments
  • 1
    Nice! Which algorithm?
  • 5
    Here one for Cortex-M in Thumb-2:
  • 1
    @Fast-Nop a linear congruential generator, really? Come on :p
  • 2
    @RememberMe Show me a faster one. ^^

    In the actual application, there's also some measurement noise being fed continuously into the randomness state so that it's physically random.
  • 3
    @RememberMe lcg, it's very simple, but i still feel proud because I debugged it by myself, and it's not meant to be anything special
  • 3
    @Fast-Nop speed isn't everything :p
    jk, LCGs work great as long as you're aware of their issues.

    I prefer xorshifts or a Mersenne Twister, but eh, done plenty of stuff using a LCG that worked okay. Of course, none of this is for cryptography, the only crypto thing I did on my own involved a Blum-Blum-Shub (yes that's a thing) generator.

    @frogstair chill, like I said, LCGs are cool. If you want to explore more try the above-mentioned BBS generator. There's a lot of cool stuff to explore in PRNGs and also in QRNGs (quasi random numbers, which are more "uniformly spread" than pseudorandom and are used for stuff like numerical integration).
  • 3
    @RememberMe Yeah sure, not suited for security related stuff. For crypto, I would of course use the sum of 128 individual LCG rolls, each clipped to 0..511, so that I would have 128 times as much randomness. ;-)
  • 5
    @Fast-Nop *eyebrow twitch*
    Could've sworn I heard my crypto professor screaming...nah, probably just the wind.
  • 0
    @RememberMe Btw, I found a faster implementation for the LGC that doesn't need the expensive modulo operation for the range mapping afterwards.

    @highlight
    /*returns a number between 0 and range-1*/
    uint16_t Hw_Rand(uint16_t range)
    {
    static uint32_t state;

    state = state * 1103515245UL + 12345UL;

    return(((state >> 16) * range) >> 16);
    }
  • 1
Add Comment