This is the new home of the egghelp.org community forum.
All data has been migrated (including user logins/passwords) to a new phpBB version.


For more information, see this announcement post. Click the X in the top right-corner of this box to dismiss this message.

How to make random pattern selection in given text file

Requests for complete scripts or modifications/fixes for scripts you didn't write. Response not guaranteed, and no thread bumping!
Post Reply
p
pranjal_ccna961
Voice
Posts: 5
Joined: Wed Feb 18, 2009 4:45 am

How to make random pattern selection in given text file

Post by pranjal_ccna961 »

How to make random pattern selection in given text file
User avatar
arfer
Master
Posts: 436
Joined: Fri Nov 26, 2004 8:45 pm
Location: Manchester, UK

Post by arfer »

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
User avatar
username
Op
Posts: 196
Joined: Thu Oct 06, 2005 9:20 am
Location: Russian Federation, Podolsk
Contact:

Post by username »

Maybe he need something like that:

Code: Select all

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: Select all

#---------------------------------------------------------------------
# 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/eggheadt ... st.tcl.txt
Архив TCL скриптов для ботов Eggdrop/Windrop:
http://egghelp.ru/
Post Reply