ok so i have a random number generator and i was wondering how to make it so i always have 7 or another certain amount of numbers that are random, how would i do that?
how many "digits long" a number is is just a matter of output formatting. So "0" is a 7 digit number if you print it as "0000000"
What you probably meant is you want numbers within a fixed range. That is.. you want numbers between [1000000,10000000)
In which case the "usual" formula for generating random numbers in a range applies:
1 2 3 4 5 6 7 8 9 10 11 12
int rand(int min, int max) // [min,max) .. ie, max is exclusive
{
int range = max-min;
return (rand() % range) + min;
}
int main()
{
srand(...);
int a_7_digit_number = rand( 1000000, 10000000 );
}
EDIT: note this assumes RAND_MAX is large enough. If you're using C++11 you'd be better off using the <random> header, rather than rand().
Did you just copy/paste my snippet? I didn't put srand() in it.
Also, strings, so you can do stuff like:
1 2 3
cout << ID;
if(ID1 < ID2)
//...
A lot easier. I think in another thread, you had a class that had something like an ID variable? That's what I'm assuming this randomizing stuff is for.