mirror of
https://github.com/QuantumLeaps/qpcpp.git
synced 2025-01-28 06:02:56 +08:00
17 lines
470 B
C++
17 lines
470 B
C++
std::uint32_t BSP::random(void) {
|
|
|
|
// lock the scheduler around l_rnd up to the (N_PHILO + 1U) ceiling
|
|
QP::QSchedStatus lockStat = QP::QXK::schedLock(N_PHILO + 1U);
|
|
|
|
// "Super-Duper" Linear Congruential Generator (LCG)
|
|
// LCG(2^32, 3*7*11*13*23, 0, seed)
|
|
//
|
|
uint32_t rnd = l_rnd * (3U*7U*11U*13U*23U);
|
|
l_rnd = rnd; // set for the next time
|
|
|
|
QP::QXK::schedUnlock(lockStat); // unlock sched after accessing l_rnd
|
|
|
|
return (rnd >> 8);
|
|
}
|
|
|