0

I want to generate a random sequence of 5000 integers within 1 and 5000 without any repetition in C++. Can anyone help me with the code to generate such a sequence?

  • 2
    1. Generate sequence of integers 1 ... 5000 2. Shuffle the sequence – MikeCAT Nov 06 '20 at 23:23
  • 1
    https://en.cppreference.com/w/cpp/algorithm/random_shuffle – drescherjm Nov 06 '20 at 23:25
  • 1
    [std::shuffle](https://en.cppreference.com/w/cpp/algorithm/random_shuffle). – Jarod42 Nov 06 '20 at 23:25
  • alternatively use a container of all numbers from 1 tilll 5000, then randomly pick one of them until you picked all – 463035818_is_not_an_ai Nov 06 '20 at 23:26
  • Which functions generates integer random numbers within a specified range? – Saumava Dey Nov 06 '20 at 23:26
  • ***Which functions generates integer random numbers within a specified range?*** You should not do that because then you will have to search to see if you already picked the number and pick again. Instead do either of the suggestions which are simpler and don't require searching or any extra work. – drescherjm Nov 06 '20 at 23:27
  • 1
    It's easy to generate random numbers within a range, almost impossible to keep them from repeating. You've been given hints for a better way to do it, use those. – Mark Ransom Nov 06 '20 at 23:28

0 Answers0