0

How can I generate random numbers in a array without each one of them repeating?

card game

28th Jul 2016, 11:16 AM
Faith Phetla
Faith Phetla - avatar
3 Réponses
+ 1
You could just generate a new random number, if it's already in the array... or use a set. This way it would already be sorted.
28th Jul 2016, 11:50 PM
Stefan
Stefan - avatar
0
I mean lyk it it must not print 2334
28th Jul 2016, 2:36 PM
Faith Phetla
Faith Phetla - avatar
0
#include <algorithm> ... int arr[] { 1,2,3,4,5 }; unsigned len = sizeof(arr)/sizeof(arr[0]); std::random_shuffle(&arr[0], &arr[len - 1]; // Now it is shuffled.
28th Jul 2016, 5:53 PM
ddrodoric