non repeat random number

Please support our C++ advertiser: Programming Forums - DaniWeb Sister Site
Reply

Join Date: Feb 2008
Posts: 25
Reputation: ckins is an unknown quantity at this point 
Solved Threads: 0
ckins ckins is offline Offline
Light Poster

non repeat random number

 
0
  #1
Mar 28th, 2008
SO here it is;
start with an array that couts random numbers I used the generate function
now check those numbers if they repeat so return true
if false is returned then you can go onto the next random_integer to check..here I use the contains function
the problem is generate is an int function that makes numbers, and I'm checking those numbers in that array with a bool function....help plz
  1. int generate(int array[], int n, int lower, int upper)
  2. {
  3. for (int i=0;i<n;i++)
  4. {
  5. array[i]=lower + rand()%(upper-lower+1);
  6. contains
  7. }
  8. return 0;
  9. }
  10. bool contains( int nums[], int random_integer)
  11. {
  12.  
  13. int size;
  14. int max;
  15. int min;
  16.  
  17. for(int index=0;index<size)
  18. {
  19. nums[index]=//initialize nums wth the numbers in generate
  20. }
  21. if (generate [random-integer-1==nums[], max, min)
  22. {
  23. generate [random_integer-1]);
  24.  
  25. cout<<random_integer<<endl;
  26. return false;//if the number is not already there then it's false and then you can check next
  27. index++;
  28. }
  29.  
  30.  
  31. else
  32. {
  33. return true;
  34. }
  35. }
  36. int main()
  37. {
  38. srand(time(0));
Reply With Quote Quick reply to this message  
Join Date: Sep 2004
Posts: 7,868
Reputation: Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute 
Solved Threads: 755
Team Colleague
Narue's Avatar
Narue Narue is offline Offline
Senior Bitch

Re: non repeat random number

 
0
  #2
Mar 28th, 2008
Um...what?
New members chased away this month: 5
Reply With Quote Quick reply to this message  
Join Date: Feb 2008
Posts: 25
Reputation: ckins is an unknown quantity at this point 
Solved Threads: 0
ckins ckins is offline Offline
Light Poster

Re: non repeat random number

 
0
  #3
Mar 28th, 2008
Originally Posted by Narue View Post
Um...what?
I'm sorry I thought I was clear; my problems is checking the numbers in my generate function with my bool contains function...
this is the error I get
error: cannot convert ‘BingoCard’ to ‘int*’ for argument ‘1’ to ‘bool contains(int*, int)’
Reply With Quote Quick reply to this message  
Join Date: Sep 2004
Posts: 7,868
Reputation: Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute 
Solved Threads: 755
Team Colleague
Narue's Avatar
Narue Narue is offline Offline
Senior Bitch

Re: non repeat random number

 
0
  #4
Mar 28th, 2008
>error: cannot convert ‘BingoCard’ to ‘int*’ for argument ‘1’ to ‘bool contains(int*, int)’
You haven't posted enough code. BingoCard isn't even mentioned in the code you posted.
New members chased away this month: 5
Reply With Quote Quick reply to this message  
Join Date: Feb 2008
Posts: 25
Reputation: ckins is an unknown quantity at this point 
Solved Threads: 0
ckins ckins is offline Offline
Light Poster

Re: non repeat random number

 
0
  #5
Mar 28th, 2008
I really don't want to post my whole code...too long. BingoCard is a struct, and the functions I'm trying to use is for that struct...it works, but I'm having problems with the functions
byw iam reading other posts and none seem to match with my problem
Reply With Quote Quick reply to this message  
Reply

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




Views: 2270 | Replies: 4
Thread Tools Search this Thread



Tag cloud for C++
About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC