# How to fill an array with random numbers?

How to write a receiving function some given number(n) generates an array of n-th dimension with numbers from 1 to n, thus these numbers are in random order

For example: input : n=5
output 5 4 3 2 1

input: n=10
output: 6 2 3 1 4 5 7 10 9 8

how to create such a collection?
September 19th 19 at 12:26
September 19th 19 at 12:28
Solution
www.cis.temple.edu/~giorgio/cis71/code/randompermute.c
random permutation is called, if anything
And I like the name "shuffle the deck"cards. - Evelyn.Ada commented on September 19th 19 at 12:31
in English it is the "random permutation" - Lucinda_Baumbach6 commented on September 19th 19 at 12:34
the couple mnogabukaf

int main()
{
std::vector v;
int n;
std::cin >> n;
std::generate_n(std::back_inserter(v), n, []{static int i = 0; return i++;});
std::random_shuffle(v.begin(), V. end());
std::copy(v.cbegin(), V. cend(), std::ostream_iterator(std::cout, " "));
} - nikki_Bashirian commented on September 19th 19 at 12:37
September 19th 19 at 12:30
Fill the array with integers from 1 to n. Then swap two elements with random indices.
Search it in Google "shuffle the numbers from 1 to n". Should be at least 4-5 well-known algorithms, but of different complexity.
needless to say – we pass by. - Evelyn.Ada commented on September 19th 19 at 12:33
: and what, sorry, what you wrote differs from what I said? - Lucinda_Baumbach6 commented on September 19th 19 at 12:36
the fact that I gave a specific answer, but you a common phrase. - nikki_Bashirian commented on September 19th 19 at 12:39
September 19th 19 at 12:32
it is necessary to make the function inside which to create a array and fill it with random numbers ( random function), and return the function will return a pointer to this array.
In the rules that says jobs are not the issue.
random() doesn't work, it is not) it can be repeated to give 5 "to 4", actually in your case, I think we should create random generator, which makes it even harder - Evelyn.Ada commented on September 19th 19 at 12:35
it's just to check if this number was previously, replace to another randomly. generally generate a fair randomness is dedicated to not a few Internet pages. - Lucinda_Baumbach6 commented on September 19th 19 at 12:38
you can come up with any stupid sorting randomname element - nikki_Bashirian commented on September 19th 19 at 12:41
I don't know what the random permutation – don't be ridiculous and go past - Lucinda_Baumbach6 commented on September 19th 19 at 12:44
the brain, no offense, here all want the best, well I hope so. When it interfered with the array indices, I remember - and it was good. - Madiso commented on September 19th 19 at 12:47

Find more questions by tags C++C