| | |
C++ Random Numbers
Please support our C++ advertiser: Intel Parallel Studio Home
![]() |
•
•
•
•
and let's say i have a range from 2 to N, what should i do to get the output only from 2 to N and not 0 to N?because what's given in the previous thread is a function to choose from 0 to N.
thank you![]()
c++ Syntax (Toggle Plain Text)
int n = 15; int random_int; random_int = (rand()%n-2)+2;
lets look at the min/max scenarios.
MIN:
Should be 2 (right?)
so you random 0. But you said +2 at the end. so you get 2. which is minimum.
MAX:
should be 15. But max of (15-2) is 13. But you added 2. So its 15.
Problem solved
=======================
I CANT GET AN IMAGE IN MY SIG :(
=======================
I CANT GET AN IMAGE IN MY SIG :(
=======================
![]() |
Similar Threads
- Compile time errors in C++ while generating random numbers (C++)
- C++ Reorder random numbers (C++)
- random numbers all different??? (C++)
Other Threads in the C++ Forum
- Previous Thread: File read problem
- Next Thread: passing linked lists through functions??
| Thread Tools | Search this Thread |
api array based beginner binary bitmap c++ c/c++ calculator char char* class code coding compile compiler console conversion count database delete deploy desktop developer directshow dll download dynamic dynamiccharacterarray email encryption error file forms fstream function functions game givemetehcodez google graph gui homeworkhelp homeworkhelper iamthwee ifstream input int java lib linkedlist linker list loop looping loops map math memory multiple news node number numbertoword output parameter pointer problem program programming project python random read recursion recursive reference rpg sorting string strings temperature template templates test text text-file tree unix url variable vector video visualstudio win32 windows winsock word wordfrequency wxwidgets




