ANSWERS: 2
  • One fairly simple way the comes to mind is to generate as many random numbers as you have lines, and assign one random number per line. Then sort the lines using the random number as the sorting key. Since there's enough memory to read in all of the lines, you should be able to use existing C++ library functions to do the sorting. For example, you could push all of the numbers into a list, paired with the random number key, then use the sort() method on the list, then pop off the values one at a time, ignoring the random key, and write the resulting number out to a file or to the console. I hope this helps.
  • I remember a simple shuffle that can shuffle anything in an array. Iterate through the array and swap each element with a randomly selected element.

Copyright 2018, Wired Ivy, LLC

Answerbag | Terms of Service | Privacy Policy