- #include "stdio.h"
- #include "time.h"
- static unsigned long int next = 1;
- void imsrand(unsigned int);
- int imrand();
- int main(void)
- {
- int it = 0;
- int array[10] = {0};
- imsrand((unsigned int)time(0));
- while(1)
- {
- for(it=0;it<10;++it)
- {
- array[it] = imrand()%100;
- }
- printf("随机整型数组为:");
- for(it=0;it<10;++it)
- {
- printf("%3d",array[it]);
- }
- printf("\\n");
- getchar();
- }
- return 0;
- }
- int imrand()
- {
- next = next*1103515245+12345;
- return (int)(next/65536)%32768;
- }
- void imsrand(unsigned int seed)
- {
- next = seed;
- }
- //该片段来自于http://www.codesnippet.cn/detail/2005201512625.html
来源: http://www.codesnippet.cn/detail/2005201512625.html