* device/include/stdlib.h: added rand prototypes
[fw/sdcc] / device / lib / rand.c
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