Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Diff: random.cpp
- Revision:
- 13:8ea85a33e37a
- Parent:
- 2:0c241937eabd
--- a/random.cpp Mon Jun 25 12:10:31 2018 +0000
+++ b/random.cpp Mon Jun 25 13:20:00 2018 +0000
@@ -8,35 +8,35 @@
bool initialized = false;
void init() {
- srand(noise.read_u16());
+ srand(((uint32_t)noise.read_u16())<<16 & ((uint32_t)noise.read_u16()));
initialized = true;
}
- uint16_t unif(const uint16_t& nlevels) {
+ uint32_t unif(const uint32_t& nlevels) {
if (!initialized) {
init();
}
- return ((uint16_t)rand()) % nlevels;
+ return ((uint32_t)rand()) % nlevels;
}
- uint16_t exponential(const uint16_t& tau_ms, const uint16_t& cutoff, const unsigned int& resolution){
+ uint32_t exponential(const uint32_t& tau, const uint32_t& cutoff, const unsigned int& resolution){
if (!initialized) {
init();
}
- double ftau = (double)tau_ms;
+ double ftau = (double)tau;
double fcutoff = (double)cutoff;
double cumulativeFraction = ((double)(rand() & resolution))/resolution;
// calculate the point (in exponential distribution) from the inverse of its cumulative density function
double point = -ftau * log(1-cumulativeFraction);
- // return as uint16 value.
+ // return as uint32 value.
// if `point` is unreasonably long, then return `cutoff` instead.
if (point > fcutoff) {
return cutoff;
} else {
- return (uint16_t)(point+0.5);
+ return (uint32_t)(point+0.5);
}
}
}