<?xml version="1.0" encoding="UTF-8"?>
<feed xmlns="http://www.w3.org/2005/Atom" xml:lang="en-gb">
	<link rel="self" type="application/atom+xml" href="https://forum.eggheads.org/app.php/feed/topic/21280" />

	<title>egghelp/eggheads community</title>
	<subtitle>Discussion of eggdrop bots, shell accounts and tcl scripts.</subtitle>
	<link href="https://forum.eggheads.org/index.php" />
	<updated>2023-05-16T11:17:55-04:00</updated>

	<author><name><![CDATA[egghelp/eggheads community]]></name></author>
	<id>https://forum.eggheads.org/app.php/feed/topic/21280</id>

		<entry>
		<author><name><![CDATA[caesar]]></name></author>
		<updated>2023-05-16T11:17:55-04:00</updated>

		<published>2023-05-16T11:17:55-04:00</published>
		<id>https://forum.eggheads.org/viewtopic.php?p=111965#p111965</id>
		<link href="https://forum.eggheads.org/viewtopic.php?p=111965#p111965"/>
		<title type="html"><![CDATA[random colors per character]]></title>

		
		<content type="html" xml:base="https://forum.eggheads.org/viewtopic.php?p=111965#p111965"><![CDATA[
After a bit of consideration, I decided to put things to a test.<br><br>The <em class="text-italics">rand</em> command (that comes with eggdrop) outputs a random value from the given LIMIT, of 0 up to LIMIT-1, thus, giving it a limit of 5, it can output the values 0, 1, 2, 3, 4.<div class="codebox"><p>Code: </p><pre><code>% set fg_colors "01 02 05 06 10 12"01 02 05 06 10 12% llength $fg_colors6%</code></pre></div>With that limit-1 from the rand this means it will start from 0 and end at 5. To test that:<div class="codebox"><p>Code: </p><pre><code>% set fg_colors "01 02 05 06 10 12"01 02 05 06 10 12% lindex $fg_colors 512% lindex $fg_colors 001</code></pre></div>And the result is correct, no need to change anything if you use the rand output on a list with <em class="text-italics">lindex</em>.<br><br>But, if you want to get a random number starting with 1 up to a certain limit, let's say 1 to 100, then you need that +1 I mentioned initially. <img class="smilies" src="https://forum.eggheads.org/images/smilies/icon_smile.gif" width="15" height="15" alt=":)" title="Smile"><p>Statistics: Posted by <a href="https://forum.eggheads.org/memberlist.php?mode=viewprofile&amp;u=187">caesar</a> — Tue May 16, 2023 11:17 am</p><hr />
]]></content>
	</entry>
		<entry>
		<author><name><![CDATA[SpiKe^^]]></name></author>
		<updated>2023-05-15T12:40:29-04:00</updated>

		<published>2023-05-15T12:40:29-04:00</published>
		<id>https://forum.eggheads.org/viewtopic.php?p=111964#p111964</id>
		<link href="https://forum.eggheads.org/viewtopic.php?p=111964#p111964"/>
		<title type="html"><![CDATA[No need for +1]]></title>

		
		<content type="html" xml:base="https://forum.eggheads.org/viewtopic.php?p=111964#p111964"><![CDATA[
caesar,<br><br>I don't agree with any of that.<br><br>[rand] works well with [lindex] and [llength], without the need for any extra math:)<p>Statistics: Posted by <a href="https://forum.eggheads.org/memberlist.php?mode=viewprofile&amp;u=7749">SpiKe^^</a> — Mon May 15, 2023 12:40 pm</p><hr />
]]></content>
	</entry>
		<entry>
		<author><name><![CDATA[CrazyCat]]></name></author>
		<updated>2023-05-15T12:40:37-04:00</updated>

		<published>2023-05-15T12:40:08-04:00</published>
		<id>https://forum.eggheads.org/viewtopic.php?p=111963#p111963</id>
		<link href="https://forum.eggheads.org/viewtopic.php?p=111963#p111963"/>
		<title type="html"><![CDATA[random colors per character]]></title>

		
		<content type="html" xml:base="https://forum.eggheads.org/viewtopic.php?p=111963#p111963"><![CDATA[
When working with rand on list, [rand [llength $list]] is perfect as list index begins at 0. llength is alway last index + 1.<p>Statistics: Posted by <a href="https://forum.eggheads.org/memberlist.php?mode=viewprofile&amp;u=691">CrazyCat</a> — Mon May 15, 2023 12:40 pm</p><hr />
]]></content>
	</entry>
		<entry>
		<author><name><![CDATA[caesar]]></name></author>
		<updated>2023-05-15T12:26:39-04:00</updated>

		<published>2023-05-15T12:26:39-04:00</published>
		<id>https://forum.eggheads.org/viewtopic.php?p=111962#p111962</id>
		<link href="https://forum.eggheads.org/viewtopic.php?p=111962#p111962"/>
		<title type="html"><![CDATA[random colors per character]]></title>

		
		<content type="html" xml:base="https://forum.eggheads.org/viewtopic.php?p=111962#p111962"><![CDATA[
Given that the <em class="text-italics">rand</em> that's implemented in eggdrop returns a random integer between 0 and limit-1, for example a [rand 10] would pick a random number from position 0 (in our case 1) up to limit (in our case it's 10) - 1, so last element will be 9, this means at least in theory, 10 will never be picked.<br><br>To put this theory to the test I mimic the <em class="text-italics">rand</em> function in tclsh:<div class="codebox"><p>Code: </p><pre><code>set max 10% for {set x 0} {$x&lt;10000} {incr x} {if {[expr {int(rand()*$max)}] == 10} {puts "match!"break}}%</code></pre></div>and then if I change from 10 to 9:<div class="codebox"><p>Code: </p><pre><code>% for {set x 0} {$x&lt;10000} {incr x} {if {[expr {int(rand()*$max)}] == 9} {puts "match!"break}}match!%</code></pre></div>Notice the lack of a match in first case. Now, if we add +1 at the end then:<div class="codebox"><p>Code: </p><pre><code>% for {set x 0} {$x&lt;1000} {incr x} {if {[expr {int(rand()*$max)} + 1] == 10} {puts "match!"break}}match!%</code></pre></div>So with +1 it works as expected.<br><br>TLDR: <em class="text-italics">rand</em> works between 0 and limit-1, thus you need to make it [rand limit + 1], else last element will never be picked.<p>Statistics: Posted by <a href="https://forum.eggheads.org/memberlist.php?mode=viewprofile&amp;u=187">caesar</a> — Mon May 15, 2023 12:26 pm</p><hr />
]]></content>
	</entry>
		<entry>
		<author><name><![CDATA[simo]]></name></author>
		<updated>2023-05-15T06:46:21-04:00</updated>

		<published>2023-05-15T06:46:21-04:00</published>
		<id>https://forum.eggheads.org/viewtopic.php?p=111961#p111961</id>
		<link href="https://forum.eggheads.org/viewtopic.php?p=111961#p111961"/>
		<title type="html"><![CDATA[random colors per character]]></title>

		
		<content type="html" xml:base="https://forum.eggheads.org/viewtopic.php?p=111961#p111961"><![CDATA[
excellent that seems to work well thanks MMX much apreciated<p>Statistics: Posted by <a href="https://forum.eggheads.org/memberlist.php?mode=viewprofile&amp;u=12505">simo</a> — Mon May 15, 2023 6:46 am</p><hr />
]]></content>
	</entry>
		<entry>
		<author><name><![CDATA[MMX]]></name></author>
		<updated>2023-05-14T18:15:50-04:00</updated>

		<published>2023-05-14T18:15:50-04:00</published>
		<id>https://forum.eggheads.org/viewtopic.php?p=111960#p111960</id>
		<link href="https://forum.eggheads.org/viewtopic.php?p=111960#p111960"/>
		<title type="html"><![CDATA[Oops ;)]]></title>

		
		<content type="html" xml:base="https://forum.eggheads.org/viewtopic.php?p=111960#p111960"><![CDATA[
Oops  <img class="smilies" src="https://forum.eggheads.org/images/smilies/icon_redface.gif" width="15" height="15" alt=":oops:" title="Embarassed"> <br>Try this one.<div class="codebox"><p>Code: </p><pre><code># random foreground and background colors from listsproc rcpc_bg {text} {set bg_colors "03 08 11"set fg_colors "01 02 05 06 10 12"foreach char [split [string trim [stripcodes * $text]] ""] {if {$char eq " "} {lappend output $char} else {lappend output "\003[lindex $fg_colors [rand [llength $fg_colors]]],[lindex $bg_colors [rand [llength $bg_colors]]]$char\003"}}return [join $output ""]}</code></pre></div><p>Statistics: Posted by <a href="https://forum.eggheads.org/memberlist.php?mode=viewprofile&amp;u=12967">MMX</a> — Sun May 14, 2023 6:15 pm</p><hr />
]]></content>
	</entry>
		<entry>
		<author><name><![CDATA[simo]]></name></author>
		<updated>2023-05-14T17:06:52-04:00</updated>

		<published>2023-05-14T17:06:52-04:00</published>
		<id>https://forum.eggheads.org/viewtopic.php?p=111959#p111959</id>
		<link href="https://forum.eggheads.org/viewtopic.php?p=111959#p111959"/>
		<title type="html"><![CDATA[random colors per character]]></title>

		
		<content type="html" xml:base="https://forum.eggheads.org/viewtopic.php?p=111959#p111959"><![CDATA[
except the proc wich has the background color as well seems to color the spaces as well while we want the spaces to be blank and only have the actual characters with fg color and bg color<p>Statistics: Posted by <a href="https://forum.eggheads.org/memberlist.php?mode=viewprofile&amp;u=12505">simo</a> — Sun May 14, 2023 5:06 pm</p><hr />
]]></content>
	</entry>
		<entry>
		<author><name><![CDATA[simo]]></name></author>
		<updated>2023-05-14T16:54:50-04:00</updated>

		<published>2023-05-14T16:54:50-04:00</published>
		<id>https://forum.eggheads.org/viewtopic.php?p=111958#p111958</id>
		<link href="https://forum.eggheads.org/viewtopic.php?p=111958#p111958"/>
		<title type="html"><![CDATA[random colors per character]]></title>

		
		<content type="html" xml:base="https://forum.eggheads.org/viewtopic.php?p=111958#p111958"><![CDATA[
excellent that seems to work well, thanks MMX<p>Statistics: Posted by <a href="https://forum.eggheads.org/memberlist.php?mode=viewprofile&amp;u=12505">simo</a> — Sun May 14, 2023 4:54 pm</p><hr />
]]></content>
	</entry>
		<entry>
		<author><name><![CDATA[MMX]]></name></author>
		<updated>2023-05-14T16:37:14-04:00</updated>

		<published>2023-05-14T16:37:14-04:00</published>
		<id>https://forum.eggheads.org/viewtopic.php?p=111957#p111957</id>
		<link href="https://forum.eggheads.org/viewtopic.php?p=111957#p111957"/>
		<title type="html"><![CDATA[random colors per character]]></title>

		
		<content type="html" xml:base="https://forum.eggheads.org/viewtopic.php?p=111957#p111957"><![CDATA[
Here are two variations with and without background color.<br>I hope they will be useful to you.<br><div class="codebox"><p>Code: </p><pre><code># completely random colors per character, no background colorsproc rcpc {text} {foreach char [split [string trim [stripcodes * $text]] ""] {lappend output "\003[expr int(rand()*15)+1]$char\003"}return [join $output ""]}# random foreground and background colors from listsproc rcpc_bg {text} {set bg_colors "03 08 11"set fg_colors "01 02 05 06 10 12"foreach char [split [string trim [stripcodes * $text]] ""] {lappend output "\003[lindex $fg_colors [rand [llength $fg_colors]]],[lindex $bg_colors [rand [llength $bg_colors]]]$char\003"}return [join $output ""]}</code></pre></div><p>Statistics: Posted by <a href="https://forum.eggheads.org/memberlist.php?mode=viewprofile&amp;u=12967">MMX</a> — Sun May 14, 2023 4:37 pm</p><hr />
]]></content>
	</entry>
		<entry>
		<author><name><![CDATA[simo]]></name></author>
		<updated>2023-05-14T12:02:45-04:00</updated>

		<published>2023-05-14T12:02:45-04:00</published>
		<id>https://forum.eggheads.org/viewtopic.php?p=111956#p111956</id>
		<link href="https://forum.eggheads.org/viewtopic.php?p=111956#p111956"/>
		<title type="html"><![CDATA[random colors per character]]></title>

		
		<content type="html" xml:base="https://forum.eggheads.org/viewtopic.php?p=111956#p111956"><![CDATA[
greetingz folks,<br><br>ive tried this to assign a color to each character in the text but it seems to do for the entire sentence instead of per character:<br><div class="codebox"><p>Code: </p><pre><code>set xfgx {00 08}set xbgx {01 02 05 06 10 12}proc wildcharcolor {text} {   set xmfgx [lindex $::xfgx [rand [llength $::xfgx]]]   set xmbgx [lindex $::xbgx [rand [llength $::xbgx]]]   set xsepx "\003${xmfgx},${xmbgx}"   set xregx $xsepx   for {set i 0} {$i&lt;=[string length $text]} {incr i} {      append xregx [string index $text $i]$xsepx   }   return $xregx }bind pub -|- !xcols pub:text:rcolorsproc  pub:text:rcolors {nick uhost hand chan text} {      if {![isatleasthalfop2017ewa $nick $chan]} { return 0 }       set text [regsub -all -- {\s{2,}} [string trim [stripcodes * $text]] { }]       putserv "privmsg $chan :[wildcharcolor $text]"}</code></pre></div><p>Statistics: Posted by <a href="https://forum.eggheads.org/memberlist.php?mode=viewprofile&amp;u=12505">simo</a> — Sun May 14, 2023 12:02 pm</p><hr />
]]></content>
	</entry>
	</feed>
