There is a much easier way to do this, using stdlib :D aaaaand here we go....
1 2 3 4 5 6 7 8 9 10
#include <stdlib>
int main()
{
for(i = 0; i < 5; i++)
{
int x = rand() % 55 + 1;
}
return 0;
}
And that's it. rand() is quite a bit simpler to use and though it has its limitations it is perfect for what we are trying to do here. This is a link to the page on rand() : http://cplusplus.com/reference/clibrary/cstdlib/rand/
If you want to check against duplicate numbers, then have a for loop that checks for repeated numbers. Okay, it will make your program run in factorial time, but hey... no duplicate numbers, and it's easy to implement.
Or, have an integer array that represents instead the time the value was returned rather than a value returned at a certain time.
Use Archaics method to get the random numbers one at a time, put each one into an array, then scan through the array at each successive number to check for duplicates. Not sure if thats the accepted way to do it, but probably how I would do it given my total n00bness.
I was going to delete my above post, and write everything from scratch, but... oops.
I actually recommend an integer array in a different sense than what we assume an... forget it, I'll just show you. How many values do you have? 56? Okay. Create a 56 element long array, each element initialized to minus one. When a certain random number is returned, return the iteration on which you got that random number into the array. If there is some value other than minus one, don't write anything in, and do not advance the counter (you'll want a while loop).
It's much more efficient than a search with a worst-case scenario performance of exactly the same as the other program (infinity), and a best-case scenario performance being linear.
-Albatross
Number of posts and counting:
1st-digit = 2nd-digit + 3rd-digit
Where: 2nd- and 3rd- digits equal their position, left to right.