Random number generator

Started by
5 comments, last by alvaro 14 years, 1 month ago
Is it possible to generate a random 6 digit number, but only using the numbers 1,2,3,4,5,6 and not having it repeat any numbers within. Example: 345621 124356 453216 1,2,3,4,5,6 has to be used once, so its basically scrambling the 6 numbers
Advertisement
Yes. Just start with the digits 123456 and shuffle them. Here's how.
Though your programming language may have a library function to do so out of the box. Ex: for C++ look up the random_shuffle() function.
I just though of something.

I guess I want to scramble the number 123456, kind of like word scrambler where you take comfort and make it trofocm

I want to do the same thing with 123456, but have a whole list of it.
Also, moved to the For Beginners forum.
Again, if you want all the permutations of a set your programming language may have a library function to do it. Ex: for C++ look up the next_permutation() function.
#include <iostream>#include <algorithm>int main() {  char s[]="123456";  do {    std::cout << s << '\n';  } while (std::next_permutation(s,s+6));}

This topic is closed to new replies.

Advertisement