mIRC Home    About    Download    Register    News    Help

Print Thread
Joined: Feb 2005
Posts: 9
K
Kaepez Offline OP
Nutrimatic drinks dispenser
OP Offline
Nutrimatic drinks dispenser
K
Joined: Feb 2005
Posts: 9
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.

Joined: Dec 2002
Posts: 1,245
M
Hoopy frood
Offline
Hoopy frood
M
Joined: Dec 2002
Posts: 1,245
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

Last edited by MikeChat; 24/05/06 01:58 AM.
Joined: Sep 2003
Posts: 4,230
D
Hoopy frood
Offline
Hoopy frood
D
Joined: Sep 2003
Posts: 4,230
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.


Link Copied to Clipboard