这个函数用来移动内存数据,其中FP_SEG(far pointer to segment)是取temp数组段地址的函数,FP_OFF(far pointer to offset)是取temp数组相对地址的函数,movedata函数的作用是把位于0040:006CH存储单元中的双字放到数组temp的声明的两个存储单元中。这样可以通过temp数组把0040:006CH处的一个16位的数送给RAND_SEED。
//rand04.cpp #include #include using namespace std; int main() { int rNum,m=20; char *ch=new char[m];
for ( int i = 0; i //大家看到了,随机种子会随着for循环在程序中设置多次 srand((unsigned)time(NULL)); rNum=1+(int)((rand()/(double)RAND_MAX)*36); //求随机值 switch (rNum){ case 1: ch[i]='a'; break ; case 2: ch[i]='b'; break ; case 3: ch[i]='c'; break ; case 4: ch[i]='d'; break ; case 5: ch[i]='e'; break ; case 6: ch[i]='f'; break ; case 7: ch[i]='g'; break ; case 8: ch[i]='h'; break ; case 9: ch[i]='i'; break ; case 10: ch[i]='j'; break ; case 11: ch[i]='k'; break ; case 12: ch[i]='l'; break ; case 13: ch[i]='m'; break ; case 14: ch[i]='n'; break ; case 15: ch[i]='o'; break ; case 16: ch[i]='p'; break ; case 17: ch[i]='q'; break ; case 18: ch[i]='r'; break ; case 19: ch[i]='s'; break ; case 20: ch[i]='t'; break ; case 21: ch[i]='u'; break ; case 22: ch[i]='v'; break ; case 23: ch[i]='w'; break ; case 24: ch[i]='x'; break ; case 25: ch[i]='y'; break ; case 26: ch[i]='z'; break ; case 27:ch[i]='0'; break; case 28:ch[i]='1'; break; case 29:ch[i]='2'; break; case 30:ch[i]='3'; break; case 31:ch[i]='4'; break; case 32:ch[i]='5'; break; case 33:ch[i]='6'; break; case 34:ch[i]='7'; break; case 35:ch[i]='8'; break; case 36:ch[i]='9'; break; }//end of switch cout< }//end of for loop