Today, because of the need, it is not realistic to randomly generate five hundred equal-length strings and write them one by one, it is also a shameful question for programmers (this is not for anyone, but for myself ). So I checked the information using the noon break and implemented this function in C language.
In VB and Delphi, there is a random function. Although the C language has been used for a long time, I have never heard of the random interface function. In fact, it also has its own, that is, srand (Time (null) and rand (). These two functions only use time changes to generate random data. The specific usage can be easily known through the following code.
The following is a simple code implementation:
- # Include <stdio. h>
- # Include <time. h>
- # Include <stdlib. h>
- Int main (INT argv, char ** argc)
- {
- Char * ss [500] = {0 };
- Int I = 0;
- Int m = 0;
- Srand (Time (null ));
- For (I = 0; I <500; I ++)
- {
- Ss [I] = malloc (10 );
- Int J = 0;
- For (m = 0; m <9; m ++)
- {
- J = rand () % 1000;
- If ('A' <= J & J <= 'Z' | 'A' <= J & J <= 'Z') // a string that generates only letters.
- {
- * (SS + I) + M) = J;
- }
- Else m --;
- }
- * (SS + I) + M) = '/0 ';
- }
- For (I = 0; I <500; I ++)
- {
- If (I % 5 = 0)
- {
- Printf ("/N ");
- }
- Printf ("% s", ss [I]);
- }
- Printf ("/N ");
- Return 0;
- }
This is also a random C language interface function that we just learned today. So take a note. If you have any better interface functions, please let me know ~~