{"id":4495,"date":"2014-03-30T11:45:57","date_gmt":"2014-03-30T11:45:57","guid":{"rendered":"https:\/\/unknownerror.org\/index.php\/2014\/03\/30\/is-windows-rand_s-thread-safe-collection-of-common-programming-errors\/"},"modified":"2014-03-30T11:45:57","modified_gmt":"2014-03-30T11:45:57","slug":"is-windows-rand_s-thread-safe-collection-of-common-programming-errors","status":"publish","type":"post","link":"https:\/\/unknownerror.org\/index.php\/2014\/03\/30\/is-windows-rand_s-thread-safe-collection-of-common-programming-errors\/","title":{"rendered":"Is Windows&#39; rand_s thread-safe?-Collection of common programming errors"},"content":{"rendered":"<p>I don&#8217;t know if rand_s is thread-safe, but it seems like it probably is, since it seems to make a round-trip to the OS for entropy. (as long as you link to the VC++ multi-thread CRT, all bets are off if you link to the single-thread one)<\/p>\n<p>If it&#8217;s supported by windows CRT, you can try a call to rand_r which is the posix reentrant version of rand. OR even better boost::random, if you&#8217;re already using boost.<\/p>\n<p>considering how pervasive multi-threading will be soon, no one should be using rand() anymore in new code &#8211; always try to use rand_r\/rand_s\/boost\/various platform-dependent secure rands\/etc.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>I don&#8217;t know if rand_s is thread-safe, but it seems like it probably is, since it seems to make a round-trip to the OS for entropy. (as long as you link to the VC++ multi-thread CRT, all bets are off if you link to the single-thread one) If it&#8217;s supported by windows CRT, you can [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1],"tags":[],"class_list":["post-4495","post","type-post","status-publish","format-standard","hentry","category-uncategorized"],"_links":{"self":[{"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/posts\/4495","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/comments?post=4495"}],"version-history":[{"count":0,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/posts\/4495\/revisions"}],"wp:attachment":[{"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/media?parent=4495"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/categories?post=4495"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/tags?post=4495"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}