qpc/doxygen/snippets/qxk_mux.c

22 lines
607 B
C
Raw Normal View History

2015-12-24 14:33:20 -05:00
QXMutex l_rndMutex; /* mutex to protect the random number generator */
void BSP_randomSeed(uint32_t seed) {
2016-03-30 18:50:33 -04:00
QXMutex_init(&l_rndMutex, N_PHILO); /* <== initialize the mutex */
2015-12-24 14:33:20 -05:00
l_rnd = seed;
}
uint32_t BSP_random(void) { /* a very cheap pseudo-random-number generator */
uint32_t rnd;
QXMutex_lock(&l_rndMutex); /* <== lock the shared random seed */
2016-03-30 18:50:33 -04:00
2015-12-24 14:33:20 -05:00
/* "Super-Duper" Linear Congruential Generator (LCG) */
rnd = l_rnd * (3U*7U*11U*13U*23U);
l_rnd = rnd; /* set for the next time */
2016-03-30 18:50:33 -04:00
2015-12-24 14:33:20 -05:00
QXMutex_unlock(&l_rndMutex); /* <== unlock the shared random seed */
return rnd;
}