954,184 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Have something to say? Contribute New Article Reply to this Article

Help! How to pull numbers from table at random

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.

scootersays
Newbie Poster
4 posts since Sep 2006
Reputation Points: 14
Solved Threads: 0
 

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.

~s.o.s~
Failure as a human
Administrator
11,938 posts since Jun 2006
Reputation Points: 3,281
Solved Threads: 733
 

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

scootersays
Newbie Poster
4 posts since Sep 2006
Reputation Points: 14
Solved Threads: 0
 

Maybe you should start here:

http://www.daniweb.com/techtalkforums/forum16.html

Hope it helped, bye.

~s.o.s~
Failure as a human
Administrator
11,938 posts since Jun 2006
Reputation Points: 3,281
Solved Threads: 733
 

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

scootersays
Newbie Poster
4 posts since Sep 2006
Reputation Points: 14
Solved Threads: 0
 

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.

~s.o.s~
Failure as a human
Administrator
11,938 posts since Jun 2006
Reputation Points: 3,281
Solved Threads: 733
 

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 , 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
Posting Expert
5,950 posts since Aug 2005
Reputation Points: 1,543
Solved Threads: 439
 

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.

scootersays
Newbie Poster
4 posts since Sep 2006
Reputation Points: 14
Solved Threads: 0
 
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();
  
  
}
iamthwee
Posting Expert
5,950 posts since Aug 2005
Reputation Points: 1,543
Solved Threads: 439
 

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.

~s.o.s~
Failure as a human
Administrator
11,938 posts since Jun 2006
Reputation Points: 3,281
Solved Threads: 733
 

This article has been dead for over three months

Post: Markdown Syntax: Formatting Help
You