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

前端 未结 6 1179
你的背包
你的背包 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:39

    If you take a closer look at 1010 you will notice that it's quite a round limit. My take on this would be to generate each number, one digit at a time and ignoring insignificant zeroes. At this point you would have a number between 0 and 1010-1 inclusive. All you're left with doing is adding a 1.

    As for random()*random(), that is the exact topic of this other question.

    Alin

提交回复
热议问题