| View previous topic :: View next topic |
| Author |
Message |
pranjal_ccna961 Voice
Joined: 18 Feb 2009 Posts: 5
|
Posted: Wed Feb 18, 2009 4:49 am Post subject: How to make random pattern selection in given text file |
|
|
| How to make random pattern selection in given text file |
|
| Back to top |
|
 |
arfer Master

Joined: 26 Nov 2004 Posts: 436 Location: Manchester, UK
|
Posted: Mon Mar 09, 2009 4:56 pm Post subject: |
|
|
The most likely reason you have no response until now is nobody understands your question. In mitigation, I accept that English is most likely your second language. Try to explain what you want with an example. _________________ I must have had nothing to do |
|
| Back to top |
|
 |
username Op

Joined: 06 Oct 2005 Posts: 196 Location: Russian Federation, Podolsk
|
Posted: Mon Mar 09, 2009 5:05 pm Post subject: |
|
|
Maybe he need something like that:
| Code: | set file [open myfile.txt r]
set data [read $file]
close $file
set lines [split $data \n]
set randline [lindex $lines [rand [llength $lines]]]
|
Or that: | Code: | #---------------------------------------------------------------------
# randlist
# TCL script for IRC-bot eggdrop.
# TCL provides specific ordering (ascii, dictionary, integer etc...)
# of lists through lsort. The proc "randlist" randomizes a list.
# On input a list, returns a randomized list.
# v0: 02-Feb-2002
#---------------------------------------------------------------------
#---------------------------------------------------------------------
# For testing purposes from the partyline.
#---------------------------------------------------------------------
bind dcc - randlist makerandlist
proc makerandlist { handle idx arg } {
set list "1 2 3 4 5 6 7 8 9 10"
putlog [randlist $list]
}
#---------------------------------------------------------------------
# Procedure randlist
#---------------------------------------------------------------------
proc randlist { list } {
# determine length of list
set listlength [llength $list]
# iterate on list, decrease length per iteration
for { set i $listlength } { $i > 1 } { incr i -1 } {
# choose random index
set randindex [rand $i]
# pick the random item
set randitem [lindex $list $randindex]
# cut the random item from the list
set list [lreplace $list $randindex $randindex]
# paste the random item at the end of the list
set list [lappend list $randitem]
}
return $list
}
| (c) http://members.fortunecity.com/eggheadtcl/randlist.tcl.txt _________________ Архив TCL скриптов для ботов Eggdrop/Windrop:
http://egghelp.ru/ |
|
| Back to top |
|
 |
|