944,167 Members | Top Members by Rank

Ad:
  • C++ Discussion Thread
  • Unsolved
  • Views: 1883
  • C++ RSS
Sep 29th, 2006
0

Help! How to pull numbers from table at random

Expand Post »
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.
Similar Threads
Reputation Points: 14
Solved Threads: 0
Newbie Poster
scootersays is offline Offline
4 posts
since Sep 2006
Sep 29th, 2006
0

Re: Help! How to pull numbers from table at random

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.
Super Moderator
Featured Poster
Reputation Points: 3241
Solved Threads: 719
Failure as a human
~s.o.s~ is offline Offline
8,873 posts
since Jun 2006
Sep 29th, 2006
0

Re: Help! How to pull numbers from table at random

Thanks for the help! I'm brand new to this site, where should I be posting these types of questions?
Reputation Points: 14
Solved Threads: 0
Newbie Poster
scootersays is offline Offline
4 posts
since Sep 2006
Sep 29th, 2006
0

Re: Help! How to pull numbers from table at random

Maybe you should start here:

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

Hope it helped, bye.
Super Moderator
Featured Poster
Reputation Points: 3241
Solved Threads: 719
Failure as a human
~s.o.s~ is offline Offline
8,873 posts
since Jun 2006
Sep 29th, 2006
0

Re: Help! How to pull numbers from table at random

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
Reputation Points: 14
Solved Threads: 0
Newbie Poster
scootersays is offline Offline
4 posts
since Sep 2006
Sep 29th, 2006
1

Re: Help! How to pull numbers from table at random

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.
Super Moderator
Featured Poster
Reputation Points: 3241
Solved Threads: 719
Failure as a human
~s.o.s~ is offline Offline
8,873 posts
since Jun 2006
Sep 29th, 2006
0

Re: Help! How to pull numbers from table at random

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:

C++ Syntax (Toggle Plain Text)
  1. +table 1+ +table 2+
  2. -------- ---------
  3. john rachel
  4. -------- --------
  5. amy sarah
  6. -------- --------
  7. 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.
Featured Poster
Reputation Points: 1536
Solved Threads: 431
Posting Expert
iamthwee is offline Offline
5,865 posts
since Aug 2005
Sep 29th, 2006
1

Re: Help! How to pull numbers from table at random

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.
Reputation Points: 14
Solved Threads: 0
Newbie Poster
scootersays is offline Offline
4 posts
since Sep 2006
Sep 30th, 2006
0

Re: Help! How to pull numbers from table at random

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?

C++ Syntax (Toggle Plain Text)
  1. #include <algorithm>
  2. #include <iostream>
  3. #include <string>
  4. #include <vector>
  5. #include <ctime>
  6.  
  7. using namespace std;
  8. int main()
  9. {
  10. srand(time(NULL));
  11. //make it so that everytime you run
  12. //the program you get different results
  13.  
  14. vector <string> vc;
  15.  
  16. vc.push_back("susan"); //fill vector
  17. vc.push_back("amy");
  18. vc.push_back("heather");
  19. vc.push_back("zoe");
  20.  
  21. cout << "The original list is:\n";
  22. for ( int i=0; i<vc.size(); i++)
  23. {
  24. cout << vc[i] <<" "; /*display the original list*/
  25. }
  26.  
  27. random_shuffle(vc.begin(), vc.end()); /* shuffle elements */
  28.  
  29. cout<<"\n\n\nThe shuffled list is:\n";
  30. for ( int i=0; i<vc.size(); i++)
  31. {
  32. cout << vc[i] <<" ";
  33. } /* display shuffled elements */
  34.  
  35. cin.get();
  36.  
  37.  
  38. }
Featured Poster
Reputation Points: 1536
Solved Threads: 431
Posting Expert
iamthwee is offline Offline
5,865 posts
since Aug 2005
Sep 30th, 2006
0

Re: Help! How to pull numbers from table at random

Click to Expand / Collapse  Quote originally posted by iamthwee ...
This?

C++ Syntax (Toggle Plain Text)
  1. #include <algorithm>
  2. #include <iostream>
  3. #include <string>
  4. #include <vector>
  5. #include <ctime>
  6.  
  7. using namespace std;
  8. int main()
  9. {
  10. srand(time(NULL));
  11. //make it so that everytime you run
  12. //the program you get different results
  13.  
  14. vector <string> vc;
  15.  
  16. vc.push_back("susan"); //fill vector
  17. vc.push_back("amy");
  18. vc.push_back("heather");
  19. vc.push_back("zoe");
  20.  
  21. cout << "The original list is:\n";
  22. for ( int i=0; i<vc.size(); i++)
  23. {
  24. cout << vc[i] <<" "; /*display the original list*/
  25. }
  26.  
  27. random_shuffle(vc.begin(), vc.end()); /* shuffle elements */
  28.  
  29. cout<<"\n\n\nThe shuffled list is:\n";
  30. for ( int i=0; i<vc.size(); i++)
  31. {
  32. cout << vc[i] <<" ";
  33. } /* display shuffled elements */
  34.  
  35. cin.get();
  36.  
  37.  
  38. }
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.
Super Moderator
Featured Poster
Reputation Points: 3241
Solved Threads: 719
Failure as a human
~s.o.s~ is offline Offline
8,873 posts
since Jun 2006

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in C++ Forum Timeline: static data member help
Next Thread in C++ Forum Timeline: The round-robin scheduler





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC