C++中生成[0, N-1]随机序列
2021-05-05 04:28
阅读:743
标签:malloc 输入 生成 and bsp ems while ++ col
输入 随机序列长度,返回 随机序列
int * randpermC(int N) { int *arr = (int*)malloc(N * sizeof(int)); int *arr2 = (int*)malloc(N * sizeof(int)); int count = 0; memset(arr, 0, N * sizeof(int)); srand(time(NULL)); while (countN) { int val = rand() % N; if (!arr[val]) { arr[val] = 1; arr2[count] = val; ++count; } } return arr2; }
arr用于标记是否使用,arr2用于记录返回的随机序列
C++中生成[0, N-1]随机序列
标签:malloc 输入 生成 and bsp ems while ++ col
原文地址:https://www.cnblogs.com/sbj123456789/p/13193710.html
下一篇:冒泡排序
文章来自:搜素材网的编程语言模块,转载请注明文章出处。
文章标题:C++中生成[0, N-1]随机序列
文章链接:http://soscw.com/index.php/essay/82571.html
文章标题:C++中生成[0, N-1]随机序列
文章链接:http://soscw.com/index.php/essay/82571.html
评论
亲,登录后才可以留言!