#include<stdio.h> #include<graphics.h> #include<stdlib.h> static unsigned long s_srand; void my_srand(unsigned long value) { static unsigned long a[] = {0x12345678,0x23456789,0x3456789a,0x456789ab,0x56789abc,0x6789abcd,0x789abcde,0x89abcdef}; static unsigned long b[] = {0x87654321,0x98765432,0xa9876543,0xba987654,0xcba98765,0xdcba9876,0xedcba987,0xfedcba98}; static unsigned char i = 0; unsigned char array_size = sizeof(a); if(value == 0) { s_srand = a[i]; i = (++i)%array_size; return; } while(1) { s_srand = (a[i%array_size]+value) & 0xffffffff; a[i] = (b[i]+s_srand) & 0xffffffff; b[i] = (a[i]*s_srand) & 0xffffffff; i = (++i)%array_size; if (s_srand != 0) break; } } unsigned long my_rand() { my_srand(1234+s_srand); return s_srand; } int main() { int i; int gdriver=DETECT,gmode; initgraph(&gdriver,&gmode,""); setcolor(6); for( i = 0; i < 1000; i++) { /*printf("rand value:0x%08x\n",rand());*/ putpixel(my_rand()%640,my_rand()%480,10); /*line(my_rand()%640,my_rand()%480,my_rand()%640,my_rand()%480);*/ } getch(); closegraph(); return 1; }
|