* device/include/stdlib.h: added rand prototypes
authorMaartenBrock <MaartenBrock@4a8a32a2-be11-0410-ad9d-d568d2c75423>
Tue, 26 Sep 2006 09:05:07 +0000 (09:05 +0000)
committerMaartenBrock <MaartenBrock@4a8a32a2-be11-0410-ad9d-d568d2c75423>
Tue, 26 Sep 2006 09:05:07 +0000 (09:05 +0000)
* device/lib/rand.c: new, added

git-svn-id: https://sdcc.svn.sourceforge.net/svnroot/sdcc/trunk/sdcc@4384 4a8a32a2-be11-0410-ad9d-d568d2c75423

ChangeLog
device/include/stdlib.h
device/lib/rand.c [new file with mode: 0644]

index 2fe21a4b7040ffafb3d16581ec6b70576d78e951..8a35160e4ac282579aedb83a3661c545e311382f 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,8 @@
+2006-09-26 Maarten Brock <sourceforge.brock AT dse.nl>
+
+       * device/include/stdlib.h: added rand prototypes
+       * device/lib/rand.c: new, added
+
 2006-09-20 Raphael Neider <rneider AT web.de>
 
        * device/lib/pic16/libio/i2c/i2cnack.c (i2c_nack): fixed ACKDT bit
index 27328370853a0d298a4b5061b298589eac9637c4..1e3dbeb87ade4369fdc107c75255e267070236ce 100644 (file)
@@ -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 (file)
index 0000000..01c9f2c
--- /dev/null
@@ -0,0 +1,38 @@
+/*-------------------------------------------------------------------------\r
+   rand.c - random number generator\r
+\r
+   Written By - Maarten Brock, sourceforge.brock@dse.nl (2006)\r
+\r
+   This library is free software; you can redistribute it and/or\r
+   modify it under the terms of the GNU Lesser General Public\r
+   License as published by the Free Software Foundation; either\r
+   version 2.1 of the License, or (at your option) any later version.\r
+\r
+   This library is distributed in the hope that it will be useful,\r
+   but WITHOUT ANY WARRANTY; without even the implied warranty of\r
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU\r
+   Lesser General Public License for more details.\r
+\r
+   You should have received a copy of the GNU Lesser General Public\r
+   License along with this library; if not, write to the Free Software\r
+   Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA\r
+\r
+   In other words, you are welcome to use, share and improve this program.\r
+   You are forbidden to forbid anyone else to use, share and improve\r
+   what you give them.   Help stamp out software-hoarding!\r
+-------------------------------------------------------------------------*/\r
+\r
+#include <stdlib.h>\r
+\r
+static unsigned long int next = 1;\r
+\r
+int rand(void)\r
+{\r
+    next = next * 1103515245UL + 12345;\r
+    return (unsigned int)(next/65536) % (RAND_MAX + 1);\r
+}\r
+\r
+void srand(unsigned int seed)\r
+{\r
+    next = seed;\r
+}\r