C Tricks(四)—— 从数组中随机选择一个元素

来源:互联网 发布:单桂敏淘宝哪个真的 编辑:程序博客网 时间:2024/05/19 02:21
arr[rand() % n];

rand() % n:等概率地获取,0 ~ n-1 中的任一元素。

0 0