You can use qrand
You can use qrand
Hi,
I have tried using the qrand() but I can't able to get the desired output. I want to generate a random set with non-repeatable alphabets. I have tried like this
Qt Code:
int array[] = {65,66,67,68,69,70,71,72}; qsrand(time(0)); for(i=0;i < SequenceCount; i++) { int j = (qrand() % SequenceCount ); qDebug() << array[j]; }To copy to clipboard, switch view to plain text mode
But in the output I see some repeatable numbers.
You mean you want to have a random permutation of the array?
Qt Code:
#include <algorithm> int array[] = {65,66,67,68,69,70,71,72}; std::shuffle(array, array+8);To copy to clipboard, switch view to plain text mode
Yes I need the same functionality U have given me. But the statementis not recognized. it says "shuffle" is not a member of the std.std::shuffle(array, array+8);
then I usedbut it is giving me some extra garbage values along with the result. likeQt Code:
std::rand_shuffle(array, array);To copy to clipboard, switch view to plain text mode.EBGCAFHD Ã…
@|%
The function name is random_shuffle and you need to include <algorithm>
If you print something to the console, it has to end with \0. This is basic C/C++ knowledge.
baluk (22nd November 2010)
Bookmarks