| View previous topic :: View next topic |
| Author |
Message |
neoclust Halfop
Joined: 14 Aug 2009 Posts: 55
|
Posted: Sun Apr 11, 2010 10:52 am Post subject: read file randomly |
|
|
| I have a file called bd.dat containing "x" lines, how to read a one line of randomly thanks |
|
| Back to top |
|
 |
raider2k Op
Joined: 01 Jan 2008 Posts: 140
|
Posted: Sun Apr 11, 2010 12:41 pm Post subject: |
|
|
after you read all of a files content into a list:
| Code: |
set output [lindex $filecontent [rand [llength $filecontent]]]
putserv "PRIVMSG $channel :$output"
|
should do the trick, at least did it for me |
|
| Back to top |
|
 |
TCL_no_TK Owner

Joined: 25 Aug 2006 Posts: 509 Location: England, Yorkshire
|
|
| Back to top |
|
 |
neoclust Halfop
Joined: 14 Aug 2009 Posts: 55
|
Posted: Sun Apr 11, 2010 4:15 pm Post subject: |
|
|
i'm using this proc
| Code: |
proc readfile {min hour day month year} {
global filenews
foreach chan [channels] {
if {[channel get $chan randnews]} {
set file [open $filenews r]
set data [read $file]
close $file
set lines [split $data \n]
set randline [lindex $lines [rand [llength $lines]]]
putserv "PRIVMSG $chan :$randline"
}
}
} |
Thanks |
|
| Back to top |
|
 |
|