{"id":2695,"date":"2016-11-05T22:03:41","date_gmt":"2016-11-05T22:03:41","guid":{"rendered":"https:\/\/raspberry-projects.com\/pi\/?p=2695"},"modified":"2016-11-05T22:03:52","modified_gmt":"2016-11-05T22:03:52","slug":"create-random-string","status":"publish","type":"post","link":"https:\/\/raspberry-projects.com\/pi\/programming-in-c\/random\/create-random-string","title":{"rendered":"Create Random String"},"content":{"rendered":"<h4>\nCreate A Random String<br \/>\n<\/h4>\n<pre>\r\n<code>\r\n\/\/#include &lt;time.h&gt;\r\n\/\/*************************************************\r\n\/\/*************************************************\r\n\/\/********** GENERATE RANDOM CHAR STRING **********\r\n\/\/*************************************************\r\n\/\/*************************************************\r\n\/\/Length\tlength including terminating null\r\nvoid generate_random_char_string (char *output_char_string, int length)\r\n{\r\n\tint count;\r\n\tstatic const char stringcharacterset[] = &quot;0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz&quot;;\r\n\r\n\tunsigned int iseed = (unsigned int)time(NULL);\t\t\t\/\/Seed srand() using time() otherwise it will start from a default value of 1\r\n\t\/\/iseed += ;\t\t\t\t\t\t\t\t\/\/&lt;&lt;&lt;Add some other value unique to your application too?\r\n\tsrand (iseed);\r\n\t\r\n\tfor (count = 0; count &lt; (length - 1); count++)\r\n\t{\r\n\t\toutput_char_string[count] = stringcharacterset[rand() % (sizeof(stringcharacterset) - 1)];\r\n\t}\r\n\r\n\toutput_char_string[(length - 1)] = 0;\r\n}\r\n<\/code><\/pre>\n<p>\n&nbsp;<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Create A Random String \/\/#include &lt;time.h&gt; \/\/************************************************* \/\/************************************************* \/\/********** GENERATE RANDOM CHAR STRING ********** \/\/************************************************* \/\/************************************************* \/\/Length length including terminating null void generate_random_char_string (char *output_char_string, int length) { int count; static const char stringcharacterset[] = &quot;0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz&quot;; unsigned int iseed = (unsigned int)time(NULL); \/\/Seed srand() using time() otherwise it will start from a default value of [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[46],"tags":[],"class_list":["post-2695","post","type-post","status-publish","format-standard","hentry","category-random"],"_links":{"self":[{"href":"https:\/\/raspberry-projects.com\/pi\/wp-json\/wp\/v2\/posts\/2695","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/raspberry-projects.com\/pi\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/raspberry-projects.com\/pi\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/raspberry-projects.com\/pi\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/raspberry-projects.com\/pi\/wp-json\/wp\/v2\/comments?post=2695"}],"version-history":[{"count":1,"href":"https:\/\/raspberry-projects.com\/pi\/wp-json\/wp\/v2\/posts\/2695\/revisions"}],"predecessor-version":[{"id":2696,"href":"https:\/\/raspberry-projects.com\/pi\/wp-json\/wp\/v2\/posts\/2695\/revisions\/2696"}],"wp:attachment":[{"href":"https:\/\/raspberry-projects.com\/pi\/wp-json\/wp\/v2\/media?parent=2695"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/raspberry-projects.com\/pi\/wp-json\/wp\/v2\/categories?post=2695"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/raspberry-projects.com\/pi\/wp-json\/wp\/v2\/tags?post=2695"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}