Random generation functions in C Language

Source: Internet
Author: User

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:

  1. # Include <stdio. h>
  2. # Include <time. h>
  3. # Include <stdlib. h>

  4. Int main (INT argv, char ** argc)
  5. {
  6. Char * ss [500] = {0 };
  7. Int I = 0;
  8. Int m = 0;

  9. Srand (Time (null ));

  10. For (I = 0; I <500; I ++)
  11. {
  12. Ss [I] = malloc (10 );
  13. Int J = 0;
  14. For (m = 0; m <9; m ++)
  15. {
  16. J = rand () % 1000;
  17. If ('A' <= J & J <= 'Z' | 'A' <= J & J <= 'Z') // a string that generates only letters.
  18. {
  19. * (SS + I) + M) = J;
  20. }
  21. Else m --;
  22. }
  23. * (SS + I) + M) = '/0 ';
  24. }

  25. For (I = 0; I <500; I ++)
  26. {
  27. If (I % 5 = 0)
  28. {
  29. Printf ("/N ");
  30. }
  31. Printf ("% s", ss [I]);
  32. }

  33. Printf ("/N ");

  34. Return 0;
  35. }

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 ~~

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.