Doesnt seem to work dude
i think you needed an extra setting of %name in here
while $lines(file.txt) {
var %name = $read(file.txt)while $readn == $calc(1 + $lines(file2.txt)) {
Even then it has a logic problem,
I see what your idea was, with the second while loop keep rechoosing a random line until it is not the same line as to be outputed onto, problem is your removing the lines from the source file, so assuming 4 nicks nick1 to nick4 in that order in the source file, it might do the following...
random pick line2 (nick2) place it in the out file and delete line2 (3 lines left in source nick1,3,4)
random pick line2 (nick3) and reject it as its output line2 (3 lines left in source nick1,3,4)
random pick line1 (nick2) place it in the out file and delete line1 (2 lines left in source nick3,4)
random pick line1 (nick3) place it in the out file and delete line1 (1 lines left in source nick4)
random pick line1 (nick4) place it in the out file and delete line1
Result
nick2
nick1
nick3
nick4
I pulled this one out from another script and patched it up to work on its own.
;
;Usage $randfile(<source file>,<destination file>)
;example !.echo -q $randfile(file.txt,file2.txt)
;
alias randfile {
if ($lines($1) == 1) { write -c $+(",$2,") $read($1,nt,1) | return }
;
window -c @hw.file1 | window -hn @hw.file1
window -c @hw.file2 | window -hn @hw.file2
;
filter -fwcn $1 @hw.file1
var %doing = 1
while ($line(@hw.file1,0)) {
var %remaining = $v1
var %line.inwin = $rand(1,%remaining)
var %line.infile = $gettok($line(@hw.file1,%line.inwin),1 ,32)
var %line.content = $gettok($line(@hw.file1,%line.inwin),2-,32)
while ((%line.infile == %doing) && (%remaining > 1)) {
var %line.inwin = $rand(1,%remaining)
var %line.infile = $gettok($line(@hw.file1,%line.inwin),1 ,32)
var %line.content = $gettok($line(@hw.file1,%line.inwin),2-,32)
}
dline @hw.file1 %line.inwin
if (%line.infile != %doing) {
aline @hw.file2 %line.content
}
else {
var %line.toswap = $rand(1,$calc(%doing - 1))
aline @hw.file2 $line(@hw.file2,%line.toswap)
rline @hw.file2 %line.toswap %line.content
}
inc %doing
}
savebuf @hw.file2 $+(",$2,")
}
* warning , this wont deal with blank lines well at all
* warning , this well randomize the lines, BUT doesnt actually insure the contents are different, ie: if u had a file with 2 identicle lines it is possable one or both may appear in the same spot, but its actually one or both have replaced the other one(s)