| | |
non repeat random number
Please support our C++ advertiser: Programming Forums - DaniWeb Sister Site
![]() |
•
•
Join Date: Feb 2008
Posts: 25
Reputation:
Solved Threads: 0
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
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
cpp Syntax (Toggle Plain Text)
int generate(int array[], int n, int lower, int upper) { for (int i=0;i<n;i++) { array[i]=lower + rand()%(upper-lower+1); contains } return 0; } bool contains( int nums[], int random_integer) { int size; int max; int min; for(int index=0;index<size) { nums[index]=//initialize nums wth the numbers in generate } if (generate [random-integer-1==nums[], max, min) { generate [random_integer-1]); cout<<random_integer<<endl; return false;//if the number is not already there then it's false and then you can check next index++; } else { return true; } } int main() { srand(time(0));
![]() |
Similar Threads
- Help needed filling array with unique random numbers (C++)
- Random Numbers on button (Java)
- C++ Random Numbers (C++)
- how to count integer from random number (C)
- random number (C++)
- Random number generator (Java)
Other Threads in the C++ Forum
- Previous Thread: Class Template Problem - Constructor Issues - Please help
- Next Thread: Going insane, please help!
Views: 2270 | Replies: 4
| Thread Tools | Search this Thread |
Tag cloud for C++
6 add api array arrays beginner binary bitmap c++ c/c++ calculator char class classes code compile compiler console conversion convert count data delete desktop directshow dll encryption error file forms fstream function functions game getline givemetehcodez google graph homeworkhelper iamthwee ifstream input int integer java lazy lib linkedlist linux loop looping loops map math matrix memory microsoft newbie news node number output parameter pointer problem program programming project proxy python random read recursion recursive reference return sort string strings struct studio system template templates test text tree unix url variable vector video visual visualstudio win32 windows winsock word wordfrequency wxwidgets






