| 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 |
extern "C" { |
| 25 |
#include "stdlib.h" |
| 26 |
} |
| 27 |
|
| 28 |
void randomSeed(unsigned long seed) |
| 29 |
{ |
| 30 |
if (seed != 0) { |
| 31 |
srandom(seed); |
| 32 |
} |
| 33 |
} |
| 34 |
|
| 35 |
long random(long howbig) |
| 36 |
{ |
| 37 |
if (howbig == 0) { |
| 38 |
return 0; |
| 39 |
} |
| 40 |
return random() % howbig; |
| 41 |
} |
| 42 |
|
| 43 |
long random(long howsmall, long howbig) |
| 44 |
{ |
| 45 |
if (howsmall >= howbig) { |
| 46 |
return howsmall; |
| 47 |
} |
| 48 |
long diff = howbig - howsmall; |
| 49 |
return random(diff) + howsmall; |
| 50 |
} |
| 51 |
|
| 52 |
long map(long x, long in_min, long in_max, long out_min, long out_max) |
| 53 |
{ |
| 54 |
return (x - in_min) * (out_max - out_min) / (in_max - in_min) + out_min; |
| 55 |
} |
| 56 |
|
| 57 |
unsigned int makeWord(unsigned int w) { return w; } |
| 58 |
unsigned int makeWord(unsigned char h, unsigned char l) { return (h << 8) | l; } |