|
| 1 | +/* -*- mode: jde; c-basic-offset: 2; indent-tabs-mode: nil -*- */ |
| 2 | + |
| 3 | +/* |
| 4 | + Part of the Wiring project - http://wiring.org.co |
| 5 | + Copyright (c) 2004-06 Hernando Barragan |
| 6 | + Modified 13 August 2006, David A. Mellis for Arduino - http://www.arduino.cc/ |
| 7 | + |
| 8 | + This library is free software; you can redistribute it and/or |
| 9 | + modify it under the terms of the GNU Lesser General Public |
| 10 | + License as published by the Free Software Foundation; either |
| 11 | + version 2.1 of the License, or (at your option) any later version. |
| 12 | +
|
| 13 | + This library is distributed in the hope that it will be useful, |
| 14 | + but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 15 | + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
| 16 | + Lesser General Public License for more details. |
| 17 | +
|
| 18 | + You should have received a copy of the GNU Lesser General |
| 19 | + Public License along with this library; if not, write to the |
| 20 | + Free Software Foundation, Inc., 59 Temple Place, Suite 330, |
| 21 | + Boston, MA 02111-1307 USA |
| 22 | +*/ |
| 23 | + |
| 24 | +#ifdef __cplusplus |
| 25 | +extern "C" { |
| 26 | + #include "stdlib.h" |
| 27 | +} |
| 28 | +#else |
| 29 | + #include "stdlib.h" |
| 30 | +#endif |
| 31 | + |
| 32 | +void randomSeed(unsigned long seed) |
| 33 | +{ |
| 34 | + if (seed != 0) { |
| 35 | + srand(seed); |
| 36 | + } |
| 37 | +} |
| 38 | + |
| 39 | +long random(long howbig) |
| 40 | +{ |
| 41 | + if (howbig == 0) { |
| 42 | + return 0; |
| 43 | + } |
| 44 | + return rand() % howbig; |
| 45 | +} |
| 46 | + |
| 47 | +long random_minmax(long howsmall, long howbig) |
| 48 | +{ |
| 49 | + long diff; |
| 50 | + |
| 51 | + if (howsmall >= howbig) { |
| 52 | + return howsmall; |
| 53 | + } |
| 54 | + diff = howbig - howsmall; |
| 55 | + return random(diff) + howsmall; |
| 56 | +} |
| 57 | + |
| 58 | +long map(long x, long in_min, long in_max, long out_min, long out_max) |
| 59 | +{ |
| 60 | + return (x - in_min) * (out_max - out_min) / (in_max - in_min) + out_min; |
| 61 | +} |
| 62 | + |
| 63 | +//unsigned int makeWord(unsigned int w) { return w; } |
| 64 | +//unsigned int makeWord(unsigned char h, unsigned char l) { return (h << 8) | l; } |
0 commit comments