forked from espressif/arduino-esp32
Removed shitty random utilities
This commit is contained in:
@ -115,10 +115,6 @@ typedef bool boolean;
|
|||||||
typedef uint8_t byte;
|
typedef uint8_t byte;
|
||||||
typedef unsigned int word;
|
typedef unsigned int word;
|
||||||
|
|
||||||
#ifdef __cplusplus
|
|
||||||
long random(long, long);
|
|
||||||
#endif
|
|
||||||
void randomSeed(unsigned long);
|
|
||||||
long map(long, long, long, long, long);
|
long map(long, long, long, long, long);
|
||||||
|
|
||||||
#ifdef __cplusplus
|
#ifdef __cplusplus
|
||||||
@ -155,8 +151,6 @@ uint16_t makeWord(byte h, byte l);
|
|||||||
unsigned long pulseIn(uint8_t pin, uint8_t state, unsigned long timeout = 1000000L);
|
unsigned long pulseIn(uint8_t pin, uint8_t state, unsigned long timeout = 1000000L);
|
||||||
unsigned long pulseInLong(uint8_t pin, uint8_t state, unsigned long timeout = 1000000L);
|
unsigned long pulseInLong(uint8_t pin, uint8_t state, unsigned long timeout = 1000000L);
|
||||||
|
|
||||||
// WMath prototypes
|
|
||||||
long random(long);
|
|
||||||
#endif /* __cplusplus */
|
#endif /* __cplusplus */
|
||||||
|
|
||||||
#define _min(a,b) ((a)<(b)?(a):(b))
|
#define _min(a,b) ((a)<(b)?(a):(b))
|
||||||
|
@ -24,47 +24,9 @@
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
extern "C" {
|
extern "C" {
|
||||||
#include <stdlib.h>
|
|
||||||
#include "esp_system.h"
|
#include "esp_system.h"
|
||||||
}
|
}
|
||||||
|
|
||||||
void randomSeed(unsigned long seed)
|
|
||||||
{
|
|
||||||
if(seed != 0) {
|
|
||||||
srand(seed);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
long random(long howbig)
|
|
||||||
{
|
|
||||||
uint32_t x = esp_random();
|
|
||||||
uint64_t m = uint64_t(x) * uint64_t(howbig);
|
|
||||||
uint32_t l = uint32_t(m);
|
|
||||||
if (l < howbig) {
|
|
||||||
uint32_t t = -howbig;
|
|
||||||
if (t >= howbig) {
|
|
||||||
t -= howbig;
|
|
||||||
if (t >= howbig)
|
|
||||||
t %= howbig;
|
|
||||||
}
|
|
||||||
while (l < t) {
|
|
||||||
x = esp_random();
|
|
||||||
m = uint64_t(x) * uint64_t(howbig);
|
|
||||||
l = uint32_t(m);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return m >> 32;
|
|
||||||
}
|
|
||||||
|
|
||||||
long random(long howsmall, long howbig)
|
|
||||||
{
|
|
||||||
if(howsmall >= howbig) {
|
|
||||||
return howsmall;
|
|
||||||
}
|
|
||||||
long diff = howbig - howsmall;
|
|
||||||
return random(diff) + howsmall;
|
|
||||||
}
|
|
||||||
|
|
||||||
long map(long x, long in_min, long in_max, long out_min, long out_max) {
|
long map(long x, long in_min, long in_max, long out_min, long out_max) {
|
||||||
const long dividend = out_max - out_min;
|
const long dividend = out_max - out_min;
|
||||||
const long divisor = in_max - in_min;
|
const long divisor = in_max - in_min;
|
||||||
|
Reference in New Issue
Block a user