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.
Help for those learning Tcl or writing their own scripts.
bsdkid
Voice
Posts: 16 Joined: Wed Nov 02, 2005 1:04 am
Post
by bsdkid » Thu Dec 22, 2005 7:41 pm
Can you help me make [rand 20] without repeating till all have been used?
Sir_Fz
Revered One
Posts: 3794 Joined: Sun Apr 27, 2003 3:10 pm
Location: Lebanon
Contact:
Post
by Sir_Fz » Thu Dec 22, 2005 8:11 pm
Repeat what?
dwickie
Halfop
Posts: 76 Joined: Sat Aug 21, 2004 8:53 am
Location: /pub/beer
Post
by dwickie » Thu Dec 22, 2005 8:11 pm
one way how to do this (list putlog random numbers 0-20 without repeating)
Code: Select all
set num "0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20"
while {[llength $num]!=0} {
set index [rand [llength $num]]
putlog [lindex $num $index]
set num "[lrange $num 0 [expr $index-1]] [lrange $num [expr $index+1] end]"
}
demond
Revered One
Posts: 3073 Joined: Sat Jun 12, 2004 9:58 am
Location: San Francisco, CA
Contact:
Post
by demond » Thu Dec 22, 2005 11:16 pm
dwickie wrote: one way how to do this (list putlog random numbers 0-20 without repeating)
Code: Select all
set num "0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20"
while {[llength $num]!=0} {
set index [rand [llength $num]]
putlog [lindex $num $index]
set num "[lrange $num 0 [expr $index-1]] [lrange $num [expr $index+1] end]"
}
[string replace] should be used instead of manipulating lists
connection, sharing, dcc problems? click
<here>
before asking for scripting help, read
<this>
use
metroid
Owner
Posts: 771 Joined: Wed Jun 16, 2004 2:46 am
Post
by metroid » Fri Dec 23, 2005 3:22 am
Code: Select all
set x ""
while {[llength $x] < 20} {
lappend x [rand 20]
set x [lsort -unique $x]
}
This code will also create a list of 20 different numbers. (20 not included)
If you want it to list the numbers from 19 to 0 or 0 to 19 just change the lsort slightly.
caesar
Mint Rubber
Posts: 3778 Joined: Sun Oct 14, 2001 8:00 pm
Location: Mint Factory
Post
by caesar » Fri Dec 23, 2005 4:36 pm
[expr [rand 20] +1] to have from 1 to 20 (bouth included) not from 0 to 19.
Once the game is over, the king and the pawn go back in the same box.
metroid
Owner
Posts: 771 Joined: Wed Jun 16, 2004 2:46 am
Post
by metroid » Fri Dec 23, 2005 5:32 pm
Seeing as he said [rand 20] i didn't bother with 1 to 20 :p
Code: Select all
set x ""
while {[llength $x] < 20} {
set x [lsort -integer -unique [lappend x [expr [rand 20] + 1]]]
}
is an more compact version (not that it really matters)
bsdkid
Voice
Posts: 16 Joined: Wed Nov 02, 2005 1:04 am
Post
by bsdkid » Fri Dec 23, 2005 5:48 pm
thx guys! great job