#include<iostream> #include<stdlib> #include<ctime> #include<string> using namespacestd; string RunDemo() { string str[4]={"a","b","c","d"}; int i=rand()%10; //生成随机数取余 switch(i) { case 0: return str[0]; break; case 1:case 2: return str[1]; break; case 3:case 4:case 5: return str[2]; break; case 6:case 7:case 8:case 9: return str[3]; break; } } int main() { srand(time(0)); //srand()是随机数生成器 for(i=0;i<10;i++) cout<<RunDemo()<<endl; getchar(); return 0; }