rand.c (331B)
1 #include <stdlib.h> 2 3 #undef srand 4 #undef rand 5 6 static unsigned long next; 7 8 void 9 srand(unsigned seed) 10 { 11 next = seed; 12 } 13 14 int 15 rand(void) 16 { 17 /* 18 * next is just an arbitrary number 19 * used to generate a random number 20 * which is <= RAND_MAX 21 */ 22 next = next * 1103515245 + 12345; 23 return (unsigned)(next/65536) % (RAND_MAX + 1); 24 }