#include<stdio.h> #include<stdlib.h> #include<time.h> #define Str_num 128//字符串条数 #define Str_size 20//符串窜大小 #define Str_width 15//字符宽度 struct Rain { int x; int y; int speed; char str[Str_size]; }rain[Str_num]; char Createch() { char temp = 0; int flag = rand() % 3; if (flag==0) { temp = rand() % 26 + 'A';//产生A-Z随机数 } else if (flag == 1) { temp = rand() % 26 + 'a'; } else { temp = rand() %10 +'0'; } return temp; } void GameInit() { for (int i = 0; i< Str_num;i++) { for (int k = 0; i< Str_size;k++) { rain[i].str[k] = Createch();//对128个字符串逐个赋值 } } } int main() { srand((unsigned)time(NULL));//随机数种子 GameInit(); for (int i = 0; i < Str_num; i++) { puts(rain[i].str); } return 0; }
全部评论
(1) 回帖