Filling an array with random numbers from 1 to 10^10 in C or C++

前端 未结 6 1117
你的背包
你的背包 2021-01-27 09:50

a part of an assignment of mine is based on an array (its size is given by the user) which contains random numbers from 1 to 10^10. Then we have to find the k-th smaller number

6条回答
  •  北恋
    北恋 (楼主)
    2021-01-27 10:55

    long long get_big_rand()
    {
    
        long long result;
        do {
            result = (rand() & 0x3ff);
            result <<= 12;
            result |= (rand() & 0xfff);
            result <<= 12;
            result |= (rand() & 0xfff);
        } while (++result > 10000000000ULL);
        return result;
    }
    

提交回复
热议问题