| | |
Random selection
Please support our C++ advertiser: Intel Parallel Studio Home
![]() |
what is "CHR/2" ? If you need 8 random numbers between the values of 0 and 16, then put them in an array.
to generate a number between 0 and 15
C++ Syntax (Toggle Plain Text)
start loop generate random number between 0 and 16 first time the number has been generated ? no, then go back and generate another number yes, add to an array of generated numbers if 8 numbers have been generated than exit loop end of loop
to generate a number between 0 and 15
int x = rand() % 16 Last edited by Ancient Dragon; Nov 26th, 2008 at 9:51 pm.
Don't PM me with questions -- you might get a nasty PM in response. If you have a question then post it in one of the forums.
•
•
•
•
what is "CHR/2" ? If you need 8 random numbers between the values of 0 and 16, then put them in an array.
C++ Syntax (Toggle Plain Text)
start loop generate random number between 0 and 16 first time the number has been generated ? no, then go back and generate another number yes, add to an array of generated numbers if 8 numbers have been generated than exit loop end of loop
to generate a number between 0 and 15int x = rand() % 16
to seed the random number with srand the *best* method is as follow.
Note you only need to seed rand once in your program.
Chris
C++ Syntax (Toggle Plain Text)
#include <ctime> ... srand(time(NULL));
Note you only need to seed rand once in your program.
Chris
Knowledge is power -- But experience is everything
![]() |
Similar Threads
- random-access files (C++)
- Forms in Random access files (Visual Basic 4 / 5 / 6)
- Python noob needs random help (Python)
- random selection with drag and drop label function( help needed!! ) (Visual Basic 4 / 5 / 6)
- Random, frequent freezes. (Troubleshooting Dead Machines)
- C++ Reorder random numbers (C++)
- [Poll] Free ad impressions for your site (IT Professionals' Lounge)
- Free ad impressions for your site (IT Professionals' Lounge)
- More changes at TechTalk (DaniWeb Community Feedback)
Other Threads in the C++ Forum
- Previous Thread: Stack with Dynamic Array
- Next Thread: Help Needed : MFC change ICON
| Thread Tools | Search this Thread |
api array arrays beginner binary bitmap c++ c/c++ calculator char char* class classes coding compile compiler console conversion convert count data database delete desktop developer directshow dll dynamic dynamiccharacterarray email encryption error file forms fstream function functions game getline google graph homeworkhelper iamthwee ifstream input int integer java lib linkedlist linker linux loop looping loops map math matrix memory multiple news node number numbertoword output parameter pointer problem program programming project proxy python random read recursion recursive reference return rpg sorting string strings struct template templates test text tree unix url vector video visualstudio win32 windows winsock word wordfrequency wxwidgets






