srand

    -1热度

    2回答

    我在我的数组中存储了四个数字,00,11,22,33。当我生成一个随机数并打印它时,它显示0而不是00(当选择第一个元素时)。其他数字很好,并正确显示。如何将00存储在数组中以便它能正确显示? #include <stdio.h> #include <stdlib.h> #include <time.h> int main() { srand(time(NULL));

    -2热度

    2回答

    int* create_array(char category, int n){ int *a; a = malloc(n* sizeof(int)); for (int i = 0; i < n; i++) { int x; srand(time(NULL)); x = rand(); a[i] = x; }

    3热度

    2回答

    我正在学习C++,我似乎无法找到我的问题的答案。当我运行我的代码时,我没有遇到任何编译器错误,但当我调用函数“getVin()”(应该使用“generate()”函数生成一个随机数)时,它不会执行所以。它输出一个零。这里是我的类(来自头文件): class Vehicle { public: Vehicle(); static int generate(); con

    -4热度

    1回答

    我已经创建了此代码,每天生成一个随机整数值。 所以今天rand()会返回3,例如我每次调用它,明天它会生成另一个值。 std::vector<MyObject> myList = getMyList(); time_t t = time(NULL); tm *lt = localtime(&t); int seed = lt->tm_mday + lt->tm_mon

    2热度

    2回答

    我正在用rand()函数在C中做一个简单的例子,但函数总是返回相同的数字,尽管我使用的是srand()。 这是代码: #include <stdio.h> #include <stdlib.h> #include <time.h> int generate(int min, int max) { srand(time(NULL)); return rand() % (

    0热度

    2回答

    在一个循环中,足以将种子设置一次以获得随机数序列。函数rand如何仅基于一个种子生成很多随机数?

    0热度

    1回答

    我有一个创建大小为N的向量函数,它打乱: void rand_vector_generator(int N) { srand(time(NULL)); vector <int> perm(N); for (unsigned k=0; k<N; k++) { perm[k] = k; } random_shuffle(perm.begin

    0热度

    1回答

    有什么办法给种子随机数发生器,也指定一个上限在Swift 3?

    -2热度

    2回答

    我正在写需要填写使用2名不同的种子名单随机整数(小于1000)两个向量的程序。当我尝试使用种子时,我应该使用它给我一个非常奇怪的输出。 这里是我到目前为止已经写的代码... #include <iostream> #include <vector> #include <algorithm> #include <cstdlib> #include <ctime> using namespa

    -1热度

    1回答

    // An efficient program to randomly select a number from stream of numbers. #include <iostream> using namespace std; #include <stdlib.h> #include <time.h> /* A program to randomly select a item