cnlohr / ch32v003fun

Open source minimal stack for the ch32 line of WCH processors, including the ch32v003, a 10¢ 48 MHz RISC-V Microcontroller - as well as many other chips within the ch32v/x line.
MIT License
913 stars 142 forks source link

Added (fixed) lib_rand, simple and fast LFSR psuedo-random number generation #392

Closed ADBeta closed 2 weeks ago

ADBeta commented 3 weeks ago

from the README.md


`lib_rand` provides a simple, but effective implimentation of a Linear Feedback
Shift Register, to provide 32-bit (Psuedo)Random Number Generation for the 
CH32Vxxx Series of Microcontroller.  
This library provides 3 levels of Random Generation complexity:
* Level 1: Takes the LFSR variable, shifts and taps it then returns it as-is.
This is very fast, and provides basic Random Number Generation
* Level 2: Generates 32 random bits, which make up a 32bit value. This gives
a larger number of random values before looping and makes patterns less obvious
* Level 3: Generates two 32bit random values, then XORs them together. Provides
even more values before repeats, and is even harder to spot patterns. Uses more
CPU time.```
ADBeta commented 3 weeks ago

Feedback is fine. Would usually have checks done from the lib being tested on its own, but this lib is fresh with no users yet, so this is the initial feedback phase.

thanks

eeucalyptus commented 2 weeks ago

@ADBeta I'd like to merge the PR,could you rename the target to make the pipeline happy?

TommyMurphyTM1234 commented 2 weeks ago

Random (pun intended :-) question - is there any convenient source of a random/noise signal on the CH32V003 or other MCUs or boards that would be useful for seeding the PRNG?

ADBeta commented 2 weeks ago

@eeucalyptus Will do shortly

@TommyMurphyTM1234 I believe the ADC pins can be used, along with a few other things but they all require a lot more code that is generally unrelated, so to avoid bloat I didn't include it in the lib. I can make another example later with that functionality

TommyMurphyTM1234 commented 2 weeks ago

@TommyMurphyTM1234 I believe the ADC pins can be used, along with a few other things but they all require a lot more code that is generally unrelated, so to avoid bloat I didn't include it in the lib. I can make another example later with that functionality

Thanks @ADBeta - yes, I was wondering if such a use case could be illustrated (even in comments) in the example.

ADBeta commented 2 weeks ago

@TommyMurphyTM1234 I'll be sure to add that within the next couple days to demonstrate a common method I've seen. Thanks for the heads up

@eeucalyptus target has been fixed. Thanks for handling the PR

TommyMurphyTM1234 commented 2 weeks ago

@TommyMurphyTM1234 I'll be sure to add that within the next couple days to demonstrate a common method I've seen. Thanks for the heads up

That's great - thanks a lot. 👍