C语言中rand()不是线程安全的函数-多线程应使用rand_r()-程序员宅基地

技术标签: 算法  c++  c语言  linux  多线程  

C语言中rand()不是线程安全的函数-多线程应使用rand_r()

这是glibc中rand_r的实现:

/* This algorithm is mentioned in the ISO C standard, here extended
   for 32 bits.  */
int
rand_r (unsigned int *seed)
{
    
  unsigned int next = *seed;
  int result;

  next *= 1103515245;
  next += 12345;
  result = (unsigned int) (next / 65536) % 2048;

  next *= 1103515245;
  next += 12345;
  result <<= 10;
  result ^= (unsigned int) (next / 65536) % 1024;

  next *= 1103515245;
  next += 12345;
  result <<= 10;
  result ^= (unsigned int) (next / 65536) % 1024;

  *seed = next;

  return result;
}

来源:https://www.gnu.org/software/libc

版权声明:本文为博主原创文章,遵循 CC 4.0 BY-SA 版权协议,转载请附上原文出处链接和本声明。
本文链接:https://blog.csdn.net/weixin_44327262/article/details/105911893

智能推荐

下拉框去重_查询下拉框选中时 去重-程序员宅基地

文章浏览阅读883次。效果图 Controller//用户List&lt;User&gt;userList=userService.selectByParam(null);model.addAttribute("userId",userId);model.addAttribute("userList",userList);List&lt;User&gt;userList1=newArrayL..._查询下拉框选中时 去重

web自动化测试第13步:元素定位(2)(webdriver的所有定位方式详解)_类 'webdriver' 的未解析的特性引用 'find_element_by_xpath-程序员宅基地

文章浏览阅读2.1k次,点赞2次,收藏7次。一、webdriver中所有的定位方法介绍 在第二节里,我们就接触了webdriver中的8种基础定位方法,但是当我们在pycharm中打出:driver.find时,代码提示中其实是有18个被选项的,这次我们就来讲讲剩余这10种定位方法都是什么,以及它们之间存在的关系。首先有两个万能定位方法:find_element()寻找符合条件的第一个元素 find_elements..._类 'webdriver' 的未解析的特性引用 'find_element_by_xpath

编码练习——Java-2-流程控制_publicclasstest{publicstaticvoidmain(stringargs[])-程序员宅基地

文章浏览阅读1.1k次,点赞2次,收藏3次。条件条件语句 - ifpublic class Test { public static void main(String[] args) { int a = 100; if(a==100) { System.out.println("a的值是 100"); } }}public class Test {_publicclasstest{publicstaticvoidmain(stringargs[]){inti=1,j=0;switch(i){case

解决SpringMVC的@ResponseBody返回中文乱码_@responsebody @requestmapping 中文乱码-程序员宅基地

文章浏览阅读2.3k次。第一种:在@RequestMapping中添加produces="text/html;charset=UTF-8@ResponseBody @RequestMapping(value = "/hello",produces = "produces=text/html;charset=UTF-8") public String hello(){ List<Em..._@responsebody @requestmapping 中文乱码

SQL 调优1_show parameter dbw-程序员宅基地

文章浏览阅读440次。SQL 调优1调整的方法调整的工具内存组件调整 shared_pool data_buffer pga IO性能文件确定调整的方法:调整的流程 架构设计 建模 程序 数据库 硬件调整 每次只调整一个地方 top 消耗资源最多 执行的次数最多 执行的时间最长 达到优化的目标就不优化了 优化的过程中一定不要产生新的_show parameter dbw

ZOJ-3772 Calculate the Function(线段树,矩阵乘法)-程序员宅基地

文章浏览阅读260次。Calculate the FunctionTime Limit: 2 Seconds Memory Limit: 65536 KBYou are given a list of numbers A1 A2 .. AN and M queries. For the i-th query:The query has two parameters Li and R_calculate the function

随便推点

[亲测有用]nginx重新加载配置时候出现nginx: [emerg] invalid host in upstream-程序员宅基地

文章浏览阅读1.1w次。问题描述nginx重新加载配置时候出现nginx: [emerg] invalid host in upstream “http://1.15.xxx.xxx:3001” in /usr/local/nginx解决方案改为下图所示_nginx: [emerg] invalid host in upstream

Unity3D说明文档翻译-Mobile Keyboard_touchscreenkeyboard.open-程序员宅基地

文章浏览阅读1.7k次。Mobile Keyboard手机键盘In most cases, Unity will handle keyboard input automatically for GUI elements but it is also easy to show the keyboard on demand from a script.在大多数情况下,Unity将通过GUI元素自动处理键盘输入,但_touchscreenkeyboard.open

scrapy读取settings.py文件_scrapy获取settings文件中的内容、-程序员宅基地

文章浏览阅读362次。 get_project_settingsfrom scrapy.utils.project import get_project_settings def __init__(self): #读取设置 self.mySetting = get_project_settings() #get获取参数 self.timeo..._scrapy获取settings文件中的内容、

Win 10开启人类迈进智能世界的大门_人类正在迈进智能世界-程序员宅基地

文章浏览阅读8.3k次。3月18日,从微软硬件工程大会(WinHEC 2015)上传来好消息:今年夏天,Win 10将要正式发布.Win 10发布,有何新意?微软新领导人纳德拉(Nadella)主张:运计算,大数据与人工智能是软件支撑世界的未来.实际上,Win 10开启了未来智能世界的大门.为什么?我们要注意的是,Win 10内置了语音识别接口,使得人用语音能够与系统直接交互,_人类正在迈进智能世界

PCB的WIP系統如何做?_pcb wipdata-程序员宅基地

文章浏览阅读2.6k次。由於最近在處理一個線路板(PCB)的軟件.由於線路板的生產要求很多,而且要經過很多的工藝流程.如果確保能正常交貨以及了解生產的各種狀態,以及了解現場各個工序的狀態,這幾乎成了PCB企業的一個難題.生產管理是整個生產的關鍵.以至於有一些生產經理,用了系統後感覺很麻煩,感覺還不如手工做得好,於是就放棄了WIP.實行手工過帳.但是走了一段時間後,感覺需要的數據不能及時了解到.不如用系統,於是WIP系統也_pcb wipdata

InnoDB: Error: io_setup() failed with EAGAIN after 5 attempts_[error] innodb: io_setup() failed with eagain afte-程序员宅基地

文章浏览阅读1.5k次。在一台服务器中以各数据库的备份文件为数据文件启动多个MySQL实例供SQL Review使用。之前运行一直没有问题(最多的时候有23个MySQL实例同时运行),后来新配置了一台服务器,启动其对应的实例时失败。部分错误日志如下:……140505 16:05:59 InnoDB: Using Linux native AIO140505 16:05:59 InnoDB: Warning: io_se..._[error] innodb: io_setup() failed with eagain after 5 attempts. [error] inno

推荐文章

热门文章

相关标签