mIRC Homepage
I'm back for more help, yet again.

What I need is an efficient way to copy six random lines from one text file into another while ensuring that none of the lines are duplicates of each other.

A possible solution I thought of would involve using $rand() and storing six values generated, then comparing each of the six values to make sure that none are equal before using $read() off the values that were stored. Seems like there might be a better method, though.
you might try something like this

Code:
alias select6 {
  var %lines = ""
  var %num = ""
  var %i = 1
  var %fileL = $lines(overthehill.txt)
  :start
  var %num = $r(1,%fileL)
  if (%num isin %lines) { goto start }
  var %lines = %lines %num
  inc %i
  if (%i > 6) { goto next }
  else goto start
  :next
  var %i = 1
  while (%i <= 6) {
    echo -a $read(overthehill.txt,$gettok(%lines,%i,32))
    inc %i
  }
}


fixed errors, but dave's is prolly better anyway
im going to assume the first file has 6 or MORE line in it, or else your in the poo.

Code:
alias example {
  var %list
  var %i = 6
  while (%i) {
    var %text = $read(firstfile.txt,nt) | while ($istok(%list,$readn,32)) { var %text = $read(firstfile.txt,nt) }
    var %list = %list $readn
    write secondfile.txt %text
    dec %i
  }
}

* code untested, should work tho.
© mIRC Discussion Forums