randomize()因该是一样的吧,关键是怎样在一秒内使多次运行的srand(time(NULL))的值不一样.3q
看看这个,我自己写的一个随机出题小程序:
#include<stdio.h> #include<stdlib.h> int jia() {int a,b; randomize(); a=random(100); randomize(); b=random(100); printf("%d+%d=",a,b); return a+b; } int jian() {int a,b; while(2) {randomize(); a=random(100); randomize(); b=random(100); if(a>=b) break; } printf("%d-%d=",a,b); return a-b; } int chen() {int a,b; randomize(); a=random(9)+1; randomize(); b=random(9)+1; printf("%d*%d=",a,b); return a*b; } int chu() {int a,b,c; while(3) {randomize(); a=random(82); randomize(); b=random(9)+1; if(a>=b) break; } c=a%b;a=a-c; printf("%d/%d=",a,b); return a/b; } void main() {int a,b,n,i;float s=0,k; printf("How many practise do you want to do?\n"); scanf("%d",&n);k=100.0/n; printf("OK,every practise %.2f'\n\n",k); for(i=1;i<=n;i++) {printf("practise %2d: ",i); randomize(); a=random(4); switch(a) {case 0:b=jia();break; case 1:b=jian();break; case 2:b=chen();break; default:b=chu(); } scanf("%d",&a); if(a==b) {printf("OK,very good!\t +%.2f'\n\n",k); s=s+k;} else printf("Sorry,it's wrong!\n\n"); } printf("\n\nThe totall=%.2f'",s); getch(); }