HOW TO DO THIS

How do I get it to loop my array and randomize its sequence every time


1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
  #include "stdafx.h"
#include<iostream>
#include<string>
#include<ctime>
using namespace std;


int main()
{

	srand(time(0));

	int a[6] ={2,4,5,8,3,2};

	for(int i=0; i< 6;++i)
	{
		a[i]= rand();
		cout<<a[i]<<endl;
	}


	system("pause");
	return 0;
}
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
#include <iostream>
#include <algorithm>
#include <ctime>

int main() {

	std::srand(std::time(0));

	const unsigned short num_elements = 5;
	int array[num_elements] = { 1, 2, 3, 4, 5 };

	std::random_shuffle(array, array + num_elements);

	for (unsigned short i = 0; i < num_elements; ++i) {
		std::cout << array[i];
	}

	std::cout << std::endl;

	std::cin.get();
	return 0;
}
Topic archived. No new replies allowed.