Using the Scientific Method, determine if this program can generate all permutat
ID: 3694268 • Letter: U
Question
Using the Scientific Method, determine if this program can generate all permutations (shuffles) of a deck of 4 cards numbered 1, 2, 3, 4 in array cards.
#include <cstdlib>
#include <iostream>
#include <time.h>
using namespace std;
int main( )
{
int cards[] = { 1, 2, 3, 4 } ;
int n = 4 , temp , i , rando ;
srand(time(NULL)); // seed rand()
for (i=0; i < n; ++i)
{
rando = rand() % n ; // pick a random spot
temp = cards[i] ; // do a swap
cards[i] = cards[ rando ];
cards[ rando ] = temp ;
}
for (int j = 0; j < n; ++j ) cout << cards[j] << ". "; cout <<" ";
system("PAUSE");
return EXIT_SUCCESS;
}
Explicitly write all hypotheses as you formulate them,
write all experiments done (pasting on some results, say of runs),
determine if something is wrong, and
if so, diagnose it precisely.