• Advertisement
Sign in to follow this  

Random number generator

This topic is 2966 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

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

Share this post


Link to post
Share on other sites
Advertisement
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.

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites
#include <iostream>
#include <algorithm>

int main() {
char s[]="123456";

do {
std::cout << s << '\n';
} while (std::next_permutation(s,s+6));
}

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement