Skip to content

Instantly share code, notes, and snippets.

@jayaprasad37
Created June 21, 2016 18:13
Show Gist options
  • Save jayaprasad37/d85eddad680bb50cf34f7f52ca80d461 to your computer and use it in GitHub Desktop.
Save jayaprasad37/d85eddad680bb50cf34f7f52ca80d461 to your computer and use it in GitHub Desktop.
Shuffling a pack of 52 cards
#include <iostream>
#include <string>
#include <ctime>
#include <algorithm>
using namespace std;
void shuffle(int arr[])
{
srand(time(0));
int j=0;
int temp = 0;
for(int i=0; i<52; i++)
{
j=rand()%52;
temp = arr[i];
arr[i]=arr[j];
arr[j]=temp;
}
}
int main()
{
int arr[52];
for(int i=0 ; i<52; i++)
{
arr[i] = i+1;
}
cout<<"The unshuffled pack is: "<<endl;;
for(int i=0 ; i<52; i++)
{
cout<<arr[i]<<" ";
}
cout<<endl;
shuffle(arr);
cout<<"The shuffled pack is: "<<endl;;
for(int i=0 ; i<52; i++)
{
cout<<arr[i]<<" ";
}
cout<<endl;
shuffle(arr);
cout<<"The shuffled pack is: "<<endl;;
for(int i=0 ; i<52; i++)
{
cout<<arr[i]<<" ";
}
cout<<endl;
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment