From: MaartenBrock Date: Tue, 26 Sep 2006 09:05:07 +0000 (+0000) Subject: * device/include/stdlib.h: added rand prototypes X-Git-Url: https://git.gag.com/?a=commitdiff_plain;h=d49ef705a2aa2ff92120fa9ab49f5f341d0eed4d;p=fw%2Fsdcc * device/include/stdlib.h: added rand prototypes * device/lib/rand.c: new, added git-svn-id: https://sdcc.svn.sourceforge.net/svnroot/sdcc/trunk/sdcc@4384 4a8a32a2-be11-0410-ad9d-d568d2c75423 --- diff --git a/ChangeLog b/ChangeLog index 2fe21a4b..8a35160e 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,8 @@ +2006-09-26 Maarten Brock + + * device/include/stdlib.h: added rand prototypes + * device/lib/rand.c: new, added + 2006-09-20 Raphael Neider * device/lib/pic16/libio/i2c/i2cnack.c (i2c_nack): fixed ACKDT bit diff --git a/device/include/stdlib.h b/device/include/stdlib.h index 27328370..1e3dbeb8 100644 --- a/device/include/stdlib.h +++ b/device/include/stdlib.h @@ -43,4 +43,9 @@ extern void _itoa(unsigned int, char*, unsigned char); extern void _ultoa(unsigned long, char*, unsigned char); extern void _ltoa(unsigned long, char*, unsigned char); + +#define RAND_MAX 32767 + +int rand(void); +void srand(unsigned int seed); #endif diff --git a/device/lib/rand.c b/device/lib/rand.c new file mode 100644 index 00000000..01c9f2c5 --- /dev/null +++ b/device/lib/rand.c @@ -0,0 +1,38 @@ +/*------------------------------------------------------------------------- + rand.c - random number generator + + Written By - Maarten Brock, sourceforge.brock@dse.nl (2006) + + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Lesser General Public + License as published by the Free Software Foundation; either + version 2.1 of the License, or (at your option) any later version. + + This library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General Public + License along with this library; if not, write to the Free Software + Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + + In other words, you are welcome to use, share and improve this program. + You are forbidden to forbid anyone else to use, share and improve + what you give them. Help stamp out software-hoarding! +-------------------------------------------------------------------------*/ + +#include + +static unsigned long int next = 1; + +int rand(void) +{ + next = next * 1103515245UL + 12345; + return (unsigned int)(next/65536) % (RAND_MAX + 1); +} + +void srand(unsigned int seed) +{ + next = seed; +}