Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/FastLED/FastLED.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMark Kriegsman <1334634+kriegsman@users.noreply.github.com>2020-02-11 18:19:42 +0300
committerGitHub <noreply@github.com>2020-02-11 18:19:42 +0300
commit1e6e56b49d22778f8a9649633996d01545aef1be (patch)
tree1af04905fc1a44b1725dd28befba2da48529f239
parent89e83a930587f5a6bb5a7246f88330958ebbadcc (diff)
parent63b254ea0eaabc4aa8926acdb6dd6cac32b98e43 (diff)
Merge pull request #916 from grandinquisitor/master
On ATtiny (only) where there is no hardware multiplier, convert use shifts&adds to achieve multiplication by the chosen LCG constant in 'random' function.
-rw-r--r--lib8tion/random8.h10
1 files changed, 8 insertions, 2 deletions
diff --git a/lib8tion/random8.h b/lib8tion/random8.h
index ba60cf57..d834abd5 100644
--- a/lib8tion/random8.h
+++ b/lib8tion/random8.h
@@ -12,13 +12,19 @@
#define FASTLED_RAND16_2053 ((uint16_t)(2053))
#define FASTLED_RAND16_13849 ((uint16_t)(13849))
+#if defined(LIB8_ATTINY)
+#define APPLY_FASTLED_RAND16_2053(x) (x << 11) + (x << 2) + x
+#else
+#define APPLY_FASTLED_RAND16_2053(x) (x * FASTLED_RAND16_2053)
+#endif
+
/// random number seed
extern uint16_t rand16seed;// = RAND16_SEED;
/// Generate an 8-bit random number
LIB8STATIC uint8_t random8()
{
- rand16seed = (rand16seed * FASTLED_RAND16_2053) + FASTLED_RAND16_13849;
+ rand16seed = APPLY_FASTLED_RAND16_2053(rand16seed) + FASTLED_RAND16_13849;
// return the sum of the high and low bytes, for better
// mixing and non-sequential correlation
return (uint8_t)(((uint8_t)(rand16seed & 0xFF)) +
@@ -28,7 +34,7 @@ LIB8STATIC uint8_t random8()
/// Generate a 16 bit random number
LIB8STATIC uint16_t random16()
{
- rand16seed = (rand16seed * FASTLED_RAND16_2053) + FASTLED_RAND16_13849;
+ rand16seed = APPLY_FASTLED_RAND16_2053(rand16seed) + FASTLED_RAND16_13849;
return rand16seed;
}