egghelp.org community Forum Index
[ egghelp.org home | forum home ]
egghelp.org community
Discussion of eggdrop bots, shell accounts and tcl scripts.
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

How to make random pattern selection in given text file

 
Post new topic   Reply to topic    egghelp.org community Forum Index -> Script Requests
View previous topic :: View next topic  
Author Message
pranjal_ccna961
Voice


Joined: 18 Feb 2009
Posts: 5

PostPosted: Wed Feb 18, 2009 4:49 am    Post subject: How to make random pattern selection in given text file Reply with quote

How to make random pattern selection in given text file
Back to top
View user's profile Send private message
arfer
Master


Joined: 26 Nov 2004
Posts: 436
Location: Manchester, UK

PostPosted: Mon Mar 09, 2009 4:56 pm    Post subject: Reply with quote

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
View user's profile Send private message
username
Op


Joined: 06 Oct 2005
Posts: 196
Location: Russian Federation, Podolsk

PostPosted: Mon Mar 09, 2009 5:05 pm    Post subject: Reply with quote

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
View user's profile Send private message Send e-mail Visit poster's website
Display posts from previous:   
Post new topic   Reply to topic    egghelp.org community Forum Index -> Script Requests All times are GMT - 4 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Forum hosting provided by Reverse.net

Powered by phpBB © 2001, 2005 phpBB Group
subGreen style by ktauber