1a267194100726de2b4e0c000adc00af4bbf47d6
[fw/sdcc] / device / lib / rand.c
1 /*-------------------------------------------------------------------------\r
2    rand.c - random number generator\r
3 \r
4    Written By - Maarten Brock, sourceforge.brock@dse.nl (2006)\r
5 \r
6    This library is free software; you can redistribute it and/or\r
7    modify it under the terms of the GNU Lesser General Public\r
8    License as published by the Free Software Foundation; either\r
9    version 2.1 of the License, or (at your option) any later version.\r
10 \r
11    This library is distributed in the hope that it will be useful,\r
12    but WITHOUT ANY WARRANTY; without even the implied warranty of\r
13    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU\r
14    Lesser General Public License for more details.\r
15 \r
16    You should have received a copy of the GNU Lesser General Public\r
17    License along with this library; if not, write to the Free Software\r
18    Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA\r
19 \r
20    In other words, you are welcome to use, share and improve this program.\r
21    You are forbidden to forbid anyone else to use, share and improve\r
22    what you give them.   Help stamp out software-hoarding!\r
23 -------------------------------------------------------------------------*/\r
24 \r
25 #include <stdlib.h>\r
26 \r
27 static unsigned long int next = 1;\r
28 \r
29 int rand(void)\r
30 {\r
31     next = next * 1103515245UL + 12345;\r
32     return (unsigned int)(next/65536) % (RAND_MAX + 1U);\r
33 }\r
34 \r
35 void srand(unsigned int seed)\r
36 {\r
37     next = seed;\r
38 }\r