生成随机数
#include <stdio.h> static unsigned long int next = 1; void my_srand(unsigned int seed) { next = seed; } int my_rand(void) { next = next * 1103515245 + 12345; return (unsigned int)next / 65536 % 32768; } int main(void) { int count; unsigned seed; while (scanf("%u", &seed) == 1) { my_srand(seed); for (count = 0; count < 5; count++) printf("%hd\n", my_rand()); printf("q to quit:\n"); } puts("done!"); return 0; }