PPP, MAGIC: new function: magic_pow

magic_pow() returns a new random number between 0 and (2^pow)-1 included.
This commit is contained in:
Sylvain Rochet 2015-02-28 19:36:03 +01:00
parent 3686110ed2
commit bec199c4a2
2 changed files with 12 additions and 0 deletions

View File

@ -100,6 +100,11 @@ void magic_randomize(void);
*/
u32_t magic(void); /* Returns the next magic number */
/*
* Return a new random number between 0 and (2^pow)-1 included.
*/
u32_t magic_pow(u8_t pow);
#if PPP_MD5_RANDM
/*
* Fill buffer with random bytes

View File

@ -264,4 +264,11 @@ u32_t magic() {
#endif /* PPP_MD5_RANDM */
/*
* Return a new random number between 0 and (2^pow)-1 included.
*/
u32_t magic_pow(u8_t pow) {
return magic() & ~(~0UL<<pow);
}
#endif /* PPP_SUPPORT */