Each time through my loop I want to assign number1, number2, number3 and number 4 a random number from the array numbers[]. However, I don't want to repeat any of the values of the array.
If I'm not being clear: If the numbers in the array were 5, 66, 3.9 and 23, I wouldn't want number1 and number3 both holding numbers[2].
I can't test to see if one variable holds the same number as another variable because two numbers in the array may be the same.
I cant test for example if number1 holds number[2] and then exclude number[2] from the others, unless you can exclude certain ranges from random numbers? And even if you could, that would still be a hell of a lot of if statements.
That works perfectly. Thank you so much. This will definitely come in handy in future programs too.
Just one question though. The parameters you give random_shuffle. Looking at that, is random_shuffle always for arrays? And I take it saying indexes as a parameter in random_shuffle is the same as indexes[0]?
(1) Since indexes is an array, its name is a pointer to its first element. Also, since its
size is 4, indexes + 4 is a pointer to the element past the last element of the array.
(2) The random_shuffle function takes a [first, last) range as its
argument, specified by providing two random access iterators.
(3) A pointer is a random access iterator (the inverse is not necessarily true, though).
That's why I can write this -> random_shuffle(indexes, indexes + 4); and it works.