In my SQL Users table each user has a unique ID and a unique Alias. I need to randomly pull Aliases from my User table and match them with a different users User ID in another table, the Activities table. The end result would be a random pairing of team members. I need code that would do this.

This is the wrong forum for this kind of question and we dont give readymade answers in this forum. Post your effort in correct forum and then maybe you can get the answer to your question.

Thanks for the help! I'm brand new to this site, where should I be posting these types of questions?

Sorry, I must not have been clear in my original post. Thanks for clearing that up for me. I posted in the C++ forum because I want a C++ solution, not a T-SQL solution. I am already well versed in T-SQL, have explored it as a solution and found it lacking. I was led to believe that code samples are, in fact, posted on this forum when I saw the this thread:
http://www.daniweb.com/techtalkforums/thread55844.html

It's located in this forum and has code samples galor. Listen, I really do appreciate you helping me to clarify my post, but if you don't have a real solution to my dilemma, in the future just push on to the next and spare me your replies please.

Thanks

If you have a dilemma post the real question to your dilemma instead of being vague all over. And whats up with this kind of attitude? Maintain it and you would be sure to make a lot many friends here.

And as far as pushing on to the next thing is concerned, this is a public forum where everyone is free to post whatever they like unless the content is filtered by the moderator. So if you dont want to get disturbed with these dilemmas move on to a Pay Site for homework help or learn to live with this.

Member Avatar for iamthwee

What are you having problem with then? Generating random numbers in c++?

I think the following would be the best idea...

Let's say your table looked like this:

+table 1+     +table 2+
--------      ---------
 john          rachel
--------      --------
 amy           sarah
--------      --------
 Suzy          Megan

Then just shuffle all the ones in table one, using random_shuffle from <algorithm>, and shuffle all the ones in table two using random_shuffle.

Then just print them off side by side. And you have your pairs randomly assigned.

If you want a sample code just ask.

iamthwee,

You are correct. That is basically what I am after. I need a code sample that would shuffle values from a column in one table and pair them at random with values in another table. If you have a code sample I would really appreciate it.

Member Avatar for iamthwee

iamthwee,

You are correct. That is basically what I am after. I need a code sample that would shuffle values from a column in one table and pair them at random with values in another table. If you have a code sample I would really appreciate it.

This?

#include <algorithm>
#include <iostream>
#include <string>
#include <vector>
#include <ctime>

using namespace std;
int main()
{
   srand(time(NULL)); 
   //make it so that everytime you run
   //the program you get different results
 
   vector <string> vc;
   
   vc.push_back("susan"); //fill vector
   vc.push_back("amy");
   vc.push_back("heather");
   vc.push_back("zoe");
   
   cout << "The original list is:\n";
   for ( int i=0; i<vc.size(); i++)
   {
        cout << vc[i] <<" "; /*display the original list*/
   }
  
   random_shuffle(vc.begin(), vc.end()); /* shuffle elements */
   
    cout<<"\n\n\nThe shuffled list is:\n";
    for ( int i=0; i<vc.size(); i++)
    {
        cout << vc[i] <<" ";
    }  /* display shuffled elements */

  cin.get();
  
  
}

This?

#include <algorithm>
#include <iostream>
#include <string>
#include <vector>
#include <ctime>

using namespace std;
int main()
{
   srand(time(NULL)); 
   //make it so that everytime you run
   //the program you get different results
 
   vector <string> vc;
   
   vc.push_back("susan"); //fill vector
   vc.push_back("amy");
   vc.push_back("heather");
   vc.push_back("zoe");
   
   cout << "The original list is:\n";
   for ( int i=0; i<vc.size(); i++)
   {
        cout << vc[i] <<" "; /*display the original list*/
   }
  
   random_shuffle(vc.begin(), vc.end()); /* shuffle elements */
   
    cout<<"\n\n\nThe shuffled list is:\n";
    for ( int i=0; i<vc.size(); i++)
    {
        cout << vc[i] <<" ";
    }  /* display shuffled elements */

  cin.get();
  
  
}

Hmm i thought he wanted to access the database using the C++ program, pull the data in and then shuffle them. This is the normal shuffling. Anyways you did a great job understanding the guys requirement, which were pretty er... vague.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.