Help! How to pull numbers from table at random

Please support our C++ advertiser: Intel Parallel Studio Home
Reply

Join Date: Sep 2006
Posts: 4
Reputation: scootersays is an unknown quantity at this point 
Solved Threads: 0
scootersays scootersays is offline Offline
Newbie Poster

Help! How to pull numbers from table at random

 
0
  #1
Sep 29th, 2006
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.
Reply With Quote Quick reply to this message  
Join Date: Jun 2006
Posts: 7,614
Reputation: ~s.o.s~ has much to be proud of ~s.o.s~ has much to be proud of ~s.o.s~ has much to be proud of ~s.o.s~ has much to be proud of ~s.o.s~ has much to be proud of ~s.o.s~ has much to be proud of ~s.o.s~ has much to be proud of ~s.o.s~ has much to be proud of ~s.o.s~ has much to be proud of 
Solved Threads: 466
Super Moderator
Featured Poster
~s.o.s~'s Avatar
~s.o.s~ ~s.o.s~ is offline Offline
Failure as a human

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

 
0
  #2
Sep 29th, 2006
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.
I don't accept change; I don't deserve to live.
Reply With Quote Quick reply to this message  
Join Date: Sep 2006
Posts: 4
Reputation: scootersays is an unknown quantity at this point 
Solved Threads: 0
scootersays scootersays is offline Offline
Newbie Poster

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

 
0
  #3
Sep 29th, 2006
Thanks for the help! I'm brand new to this site, where should I be posting these types of questions?
Reply With Quote Quick reply to this message  
Join Date: Jun 2006
Posts: 7,614
Reputation: ~s.o.s~ has much to be proud of ~s.o.s~ has much to be proud of ~s.o.s~ has much to be proud of ~s.o.s~ has much to be proud of ~s.o.s~ has much to be proud of ~s.o.s~ has much to be proud of ~s.o.s~ has much to be proud of ~s.o.s~ has much to be proud of ~s.o.s~ has much to be proud of 
Solved Threads: 466
Super Moderator
Featured Poster
~s.o.s~'s Avatar
~s.o.s~ ~s.o.s~ is offline Offline
Failure as a human

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

 
0
  #4
Sep 29th, 2006
Maybe you should start here:

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

Hope it helped, bye.
I don't accept change; I don't deserve to live.
Reply With Quote Quick reply to this message  
Join Date: Sep 2006
Posts: 4
Reputation: scootersays is an unknown quantity at this point 
Solved Threads: 0
scootersays scootersays is offline Offline
Newbie Poster

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

 
0
  #5
Sep 29th, 2006
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
Reply With Quote Quick reply to this message  
Join Date: Jun 2006
Posts: 7,614
Reputation: ~s.o.s~ has much to be proud of ~s.o.s~ has much to be proud of ~s.o.s~ has much to be proud of ~s.o.s~ has much to be proud of ~s.o.s~ has much to be proud of ~s.o.s~ has much to be proud of ~s.o.s~ has much to be proud of ~s.o.s~ has much to be proud of ~s.o.s~ has much to be proud of 
Solved Threads: 466
Super Moderator
Featured Poster
~s.o.s~'s Avatar
~s.o.s~ ~s.o.s~ is offline Offline
Failure as a human

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

 
1
  #6
Sep 29th, 2006
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.
I don't accept change; I don't deserve to live.
Reply With Quote Quick reply to this message  
Join Date: Aug 2005
Posts: 5,264
Reputation: iamthwee is a splendid one to behold iamthwee is a splendid one to behold iamthwee is a splendid one to behold iamthwee is a splendid one to behold iamthwee is a splendid one to behold iamthwee is a splendid one to behold iamthwee is a splendid one to behold iamthwee is a splendid one to behold 
Solved Threads: 377
Featured Poster
iamthwee's Avatar
iamthwee iamthwee is offline Offline
Posting Expert

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

 
0
  #7
Sep 29th, 2006
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:

  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.
*Voted best profile in the world*
Reply With Quote Quick reply to this message  
Join Date: Sep 2006
Posts: 4
Reputation: scootersays is an unknown quantity at this point 
Solved Threads: 0
scootersays scootersays is offline Offline
Newbie Poster

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

 
1
  #8
Sep 29th, 2006
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.
Reply With Quote Quick reply to this message  
Join Date: Aug 2005
Posts: 5,264
Reputation: iamthwee is a splendid one to behold iamthwee is a splendid one to behold iamthwee is a splendid one to behold iamthwee is a splendid one to behold iamthwee is a splendid one to behold iamthwee is a splendid one to behold iamthwee is a splendid one to behold iamthwee is a splendid one to behold 
Solved Threads: 377
Featured Poster
iamthwee's Avatar
iamthwee iamthwee is offline Offline
Posting Expert

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

 
0
  #9
Sep 30th, 2006
Originally Posted by scootersays View Post
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?

  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. }
*Voted best profile in the world*
Reply With Quote Quick reply to this message  
Join Date: Jun 2006
Posts: 7,614
Reputation: ~s.o.s~ has much to be proud of ~s.o.s~ has much to be proud of ~s.o.s~ has much to be proud of ~s.o.s~ has much to be proud of ~s.o.s~ has much to be proud of ~s.o.s~ has much to be proud of ~s.o.s~ has much to be proud of ~s.o.s~ has much to be proud of ~s.o.s~ has much to be proud of 
Solved Threads: 466
Super Moderator
Featured Poster
~s.o.s~'s Avatar
~s.o.s~ ~s.o.s~ is offline Offline
Failure as a human

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

 
0
  #10
Sep 30th, 2006
Originally Posted by iamthwee View Post
This?

  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.
I don't accept change; I don't deserve to live.
Reply With Quote Quick reply to this message  
Reply

This thread is more than three months old.
Perhaps start a new thread instead?
Message:


Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC