Create  Edit  Diff  FrontPage  Index  Search  Changes  History  Source  RSS  wikifarm  Admin

ؤ - FrontPage Diff

  • Added parts are displayed like this.
  • Deleted parts are displayed like this.

It just occurred to me that if you want to eltmniaie the bias (happening when there is more than one line with the minimal random value) by using the iterative process I described above, you can actually do that in one pass over the file.Instead of keeping 1 line and 1 number (the minimum so far) in memory, keep 1 line and an array of numbers in memory. The length of the array is the maximum number of iterations, it can also be an unbounded linked list. Don't expect many iterations to be necessary, especially if RAND_MAX is big.So, when random() returns the same value as the minimal value so far, call random() twice again. Store the minimum of the two values in the second item of the array. If the first call returns the smallest of the two values, keep the old line. If the second call returns the smallest of the two values, keep the new one. If both are the same, call random() twice again, and store it in the third value of the array. And so on.For later lines, continue to compare the random() return value with the first item in the array first. When it is smaller, keep that line and drop all the further values in the array.NR0QUH  <a href="">dbaqxgpeudqv</a>