<?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/1982" />

	<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>2002-06-18T18:23:00-04:00</updated>

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

		<entry>
		<author><name><![CDATA[stdragon]]></name></author>
		<updated>2002-06-18T18:23:00-04:00</updated>

		<published>2002-06-18T18:23:00-04:00</published>
		<id>https://forum.eggheads.org/viewtopic.php?p=8143#p8143</id>
		<link href="https://forum.eggheads.org/viewtopic.php?p=8143#p8143"/>
		<title type="html"><![CDATA[Random numbers (srand)]]></title>

		
		<content type="html" xml:base="https://forum.eggheads.org/viewtopic.php?p=8143#p8143"><![CDATA[
First, rand is an eggdrop function, not a tcl function, so seeding the tcl rand generator won't do much good. Anyway, tcl's rand function is seeded automatically by tcl. (Use [expr rand()] to get a random number from it.)<br><br>Second, the eggdrop rand generator is already seeded. It's probably just a crappy algorithm.<br><br>You could try using tcl's instead, or you could use the md5 function to create pseudo-random numbers.<br><br><div class="codebox"><p>Code: </p><pre><code>set _last_rand [clock seconds]proc md5rand {len} {  global _last_rand  set r [md5 "[clock seconds] $_last_rand"]  set _last_rand $r  set x1 [string range $r 0 7]  set x2 [string range $r 8 15]  set x3 [string range $r 16 23]  set x4 [string range $r 24 31]  scan "$x1 $x2 $x3 $x4" "%x %x %x %x" i1 i2 i3 i4  return [expr ($i1 + $i2 + $i3 + $i4) % $len]}</code></pre></div>I did a little test to see the randomness of this vs. rand:<br><br>.tcl for {set i 0} {$i &lt; 100} {incr i} {lappend md5rands [md5rand 10]}<br><br>.tcl for {set i 0} {$i &lt; 100} {incr i} {lappend rands [rand 10]}<br><br>.tcl for {set i 0} {$i &lt; 100} {incr i} {lappend tclrands [expr round(rand() * 1000000) % 10]}<br><br>.tcl putlog [lsort $tclrands]<br><br><br>.tcl putlog [lsort $md5rands]<br>[13:59] 0 0 0 0 0 0 0 0 0 0 0 0 1 1 1 1 1 1 1 1 1 1 2 2 2 2 2 2 2 2 2 2 3 3 3 3 3 3 3 3 4 4 4 4 4 4 4 4 4 5 5 5 5 5 5 5 5 5 5 5 6 6 6 6 6 6 6 7 7 7 7 7 7 7 7 7 7 8 8 8 8 8 8 8 8 8 8 8 8 8 8 9 9 9 9 9 9 9 9 9<br><br>.tcl putlog [lsort $rands]<br>[13:59] 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 1 1 1 2 2 3 3 3 3 3 3 3 3 3 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 5 5 5 5 5 5 5 5 5 5 6 6 6 6 6 6 6 6 7 7 7 7 7 7 7 7 7 7 7 8 8 8 8 8 8 8 8 8 8 8 8 8 9 9 9 9 9 9 9 9 9 9 9<br><br>.tcl putlog [lsort $tclrands]<br>[13:59] 0 0 0 0 0 0 0 0 0 0 1 1 1 1 2 2 2 2 2 2 2 2 2 2 2 2 2 3 3 3 3 3 3 3 3 3 3 3 4 4 4 4 4 4 4 4 4 5 5 5 5 5 5 5 5 6 6 6 6 6 6 6 6 6 6 6 6 6 7 7 7 7 7 7 7 7 7 8 8 8 8 8 8 8 8 8 8 8 8 9 9 9 9 9 9 9 9 9 9 9<br><br>To be perfectly distributed, each number should appear 10 times. In md5rand, the most deviant waa 8 (appeared 14 times). For rand, the most deviant was 2 (appeared 2 times). For tclrand, the most deviant was 1 (appeared 4 times). You'd have to compute more statistics to really tell, but it looks like md5rand is superior.<p>Statistics: Posted by <a href="https://forum.eggheads.org/memberlist.php?mode=viewprofile&amp;u=8">stdragon</a> — Tue Jun 18, 2002 6:23 pm</p><hr />
]]></content>
	</entry>
		<entry>
		<author><name><![CDATA[Anonymous]]></name></author>
		<updated>2002-06-18T08:23:00-04:00</updated>

		<published>2002-06-18T08:23:00-04:00</published>
		<id>https://forum.eggheads.org/viewtopic.php?p=8132#p8132</id>
		<link href="https://forum.eggheads.org/viewtopic.php?p=8132#p8132"/>
		<title type="html"><![CDATA[Random numbers (srand)]]></title>

		
		<content type="html" xml:base="https://forum.eggheads.org/viewtopic.php?p=8132#p8132"><![CDATA[
Im pretty new to tcl and Im having a few problems with random numbers. What Ive got at the moment is<br><br><strong class="text-strong">putserv "PRIVMSG $chan :...[lindex $response_array [rand [llength $response_array]]]"</strong><br><br>Which works, and gives a fairly random set of responses. But its seems to pick some answers a lot more often than others, and some it misses out entirely.<br><br>In other languages Ive used you have to seed the random number generator before using it. But I cant seem to do that in my scripts.<br><br><strong class="text-strong">srand [clock clicks]</strong><br><br>gives this error<br><br><strong class="text-strong">Tcl error [do_response_chan]: invalid command name "srand"</strong><br><br>even tho srand seems to be in the tcl manual. Any ideas what Im doing wrong? Do I need to the seed the generator, or am i just being paranoid?<p>Statistics: Posted by Guest — Tue Jun 18, 2002 8:23 am</p><hr />
]]></content>
	</entry>
	</feed>
