Do all the things like ++ or -- rants, post your own rants, comment on others' rants and build your customized dev avatarSign Up
Nice! Which algorithm?
Here one for Cortex-M in Thumb-2:
@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).
Fast-Nop2705828d@RememberMe Btw, I found a faster implementation for the LGC that doesn't need the expensive modulo operation for the range mapping afterwards.
/*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);