mercredi 2 juin 2021

Please Open the requirments are different that the duplicates, How to generate n random numbers? [duplicate]

How can I get n=MAX/4 unique and sorted random numbers from the field [0,MAX] using rand() efficiently, and print them, Note: MAX is an integer?

One solution I though about is to iterate over the values [0,MAX] one by one and each time choose randomly 0(don't pick) or 1(pick this) and stop when we have n chosen.

That's so inefficient plus I may need to do infinity number of iterations.




Aucun commentaire:

Enregistrer un commentaire