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

	<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-10-16T17:00:11-04:00</updated>

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

		<entry>
		<author><name><![CDATA[egghead]]></name></author>
		<updated>2002-10-16T17:00:11-04:00</updated>

		<published>2002-10-16T17:00:11-04:00</published>
		<id>https://forum.eggheads.org/viewtopic.php?p=12032#p12032</id>
		<link href="https://forum.eggheads.org/viewtopic.php?p=12032#p12032"/>
		<title type="html"><![CDATA[Re: random number script]]></title>

		
		<content type="html" xml:base="https://forum.eggheads.org/viewtopic.php?p=12032#p12032"><![CDATA[
<blockquote class="uncited"><div>Can somone build me a script that give me a random number?<br>when I type !random 3 70 it display me a random number between 3 and 70<br><br>When you can build me one i be your slave  <img class="smilies" src="https://forum.eggheads.org/images/smilies/icon_biggrin.gif" width="15" height="15" alt=":D" title="Very Happy"></div></blockquote>USG|Shinji, there are a couple of questions/issues when writing such script.<br><br>1. The first question is whether the script should deal with integers only or floats?<br><br>2. The second question is if the script should be able to deal with negative integers?<br><br>3. The third question is whether the script must include the upper and lower integer as possible values? <br><br>4. The fourth question is how rigorous the script must check and respond to the userinput? What if the user types "!random 10 ahahah"?<br><br>5. If the script should be able to handle integers, one is bound by the maximum and minimum representable integer (MAXINT and MININT or whatever name they have on your machine <img class="smilies" src="https://forum.eggheads.org/images/smilies/icon_smile.gif" width="15" height="15" alt=":)" title="Smile"> ).<br>On most 32 bit machines this minimum and maximum are -2147483648 and 2147483647 respectively.<br><br>6. Additionally, suppose one allows negative integers on the aforementioned 32 bit machine.  <br>An (idiotic) user types: "!random -1 2147483647" i.e. the script is to find a random integer between these two values. Commonly used intermediate calculations will subtract the upper integer from the lower integer: 2147483647 - - 1 = 2147483648. This resulting integer can not be represented correctly as an integer, because it exceeds the maximum integer value. In this particular case most likely it will be represented as -2147483648. The same happens when a commonly used method adds 1 to the upper integer and this integer happens to be 2147483647. This problem can be avoided by doing all the calculations using floats and using the [expr int()] or [expr round()] functions afterwards.<br><br>My experiment can be found at:<br><a href="http://members.fortunecity.com/eggheadtcl/randomnumber.tcl.txt" class="postlink">http://members.fortunecity.com/eggheadt ... er.tcl.txt</a><br><br>1. Script handles signed decimal integers.<br>2. Script handles negative integers.<br>3. Lower and upper integer are possible random numbers too.<br>4. Script will notify user on idiotic input.<br>5. Integers must be in the range of MININT and MAXINT. It is possible to extend this range substantially by switching from integers to a mix of strings and floats.<br>6. Script uses zero [catches] <img class="smilies" src="https://forum.eggheads.org/images/smilies/icon_razz.gif" width="15" height="15" alt=":P" title="Razz"><p>Statistics: Posted by <a href="https://forum.eggheads.org/memberlist.php?mode=viewprofile&amp;u=282">egghead</a> — Wed Oct 16, 2002 5:00 pm</p><hr />
]]></content>
	</entry>
		<entry>
		<author><name><![CDATA[strikelight]]></name></author>
		<updated>2002-10-14T14:43:10-04:00</updated>

		<published>2002-10-14T14:43:10-04:00</published>
		<id>https://forum.eggheads.org/viewtopic.php?p=11982#p11982</id>
		<link href="https://forum.eggheads.org/viewtopic.php?p=11982#p11982"/>
		<title type="html"><![CDATA[Re: randomnumber script]]></title>

		
		<content type="html" xml:base="https://forum.eggheads.org/viewtopic.php?p=11982#p11982"><![CDATA[
<blockquote class="uncited"><div><blockquote class="uncited"><div><blockquote class="uncited"><div>Can somone build me a script that give me an randomnumber?<br>when I type !random 3 70 it display me a random number between 3 and 70<br><br>When you can build me one i be your slave  <img class="smilies" src="https://forum.eggheads.org/images/smilies/icon_biggrin.gif" width="15" height="15" alt=":D" title="Very Happy"></div></blockquote><div class="codebox"><p>Code: </p><pre><code>bind pub - !random shins_randproc shins_rand {nick uhost hand chan text} {  set range1 [lindex [split $text] 0]  set range2 [lindex [split $text] 1]  set range1check [string trim $range1 "0123456789"]  set range2check [string trim $range2 "0123456789"]  if {($range1 == "") || ($range2 == "") || ($range1check != "") || ($range2check != "")} {    puthelp "PRIVMSG $chan :Usage: !random &lt;min range&gt; &lt;max range&gt;"    return  }  set randnum [expr [rand [expr ($range2 + 1) - $range1]] + $range1]  puthelp "PRIVMSG $chan :Your number is: $randnum"}</code></pre></div>This is untested code.. but you get the idea..</div></blockquote>what can i do that my bot say a error to the one who use the command?<br>( [17:59:20] &lt;)Sarah&gt; [16:00] Tcl error [shins_rand]: integer value too large to represent )<br><br><span style="font-size:75%;line-height:116%">sorry for my bad english</span></div></blockquote><br> You can change:<div class="codebox"><p>Code: </p><pre><code>  set randnum [expr [rand [expr ($range2 + 1) - $range1]] + $range1]  puthelp "PRIVMSG $chan :Your number is: $randnum"</code></pre></div>  To:<br><div class="codebox"><p>Code: </p><pre><code>  if {[catch {set randnum [expr [rand [expr ($range2 + 1) - $range1]] + $range1]}]} {    puthelp "PRIVMSG $chan :Please use a lower and proper range."  } else {    puthelp "PRIVMSG $chan :Your number is: $randnum"  }</code></pre></div>Unfortunately, tcl has some limitations... Depending on your TCL version that your bot is using, it may or may not help to upgrade your TCL.<p>Statistics: Posted by <a href="https://forum.eggheads.org/memberlist.php?mode=viewprofile&amp;u=2005">strikelight</a> — Mon Oct 14, 2002 2:43 pm</p><hr />
]]></content>
	</entry>
		<entry>
		<author><name><![CDATA[Anonymous]]></name></author>
		<updated>2002-10-14T12:02:03-04:00</updated>

		<published>2002-10-14T12:02:03-04:00</published>
		<id>https://forum.eggheads.org/viewtopic.php?p=11979#p11979</id>
		<link href="https://forum.eggheads.org/viewtopic.php?p=11979#p11979"/>
		<title type="html"><![CDATA[Re: randomnumber script]]></title>

		
		<content type="html" xml:base="https://forum.eggheads.org/viewtopic.php?p=11979#p11979"><![CDATA[
<blockquote class="uncited"><div><blockquote class="uncited"><div>Can somone build me a script that give me an randomnumber?<br>when I type !random 3 70 it display me a random number between 3 and 70<br><br>When you can build me one i be your slave  <img class="smilies" src="https://forum.eggheads.org/images/smilies/icon_biggrin.gif" width="15" height="15" alt=":D" title="Very Happy"></div></blockquote><div class="codebox"><p>Code: </p><pre><code>bind pub - !random shins_randproc shins_rand {nick uhost hand chan text} {  set range1 [lindex [split $text] 0]  set range2 [lindex [split $text] 1]  set range1check [string trim $range1 "0123456789"]  set range2check [string trim $range2 "0123456789"]  if {($range1 == "") || ($range2 == "") || ($range1check != "") || ($range2check != "")} {    puthelp "PRIVMSG $chan :Usage: !random &lt;min range&gt; &lt;max range&gt;"    return  }  set randnum [expr [rand [expr ($range2 + 1) - $range1]] + $range1]  puthelp "PRIVMSG $chan :Your number is: $randnum"}</code></pre></div>This is untested code.. but you get the idea..</div></blockquote>what can i do that my bot say a error to the one who use the command?<br>( [17:59:20] &lt;)Sarah&gt; [16:00] Tcl error [shins_rand]: integer value too large to represent )<br><br><span style="font-size:75%;line-height:116%">sorry for my bad english</span><p>Statistics: Posted by Guest — Mon Oct 14, 2002 12:02 pm</p><hr />
]]></content>
	</entry>
		<entry>
		<author><name><![CDATA[ppslim]]></name></author>
		<updated>2002-10-14T11:29:39-04:00</updated>

		<published>2002-10-14T11:29:39-04:00</published>
		<id>https://forum.eggheads.org/viewtopic.php?p=11977#p11977</id>
		<link href="https://forum.eggheads.org/viewtopic.php?p=11977#p11977"/>
		<title type="html"><![CDATA[random number script]]></title>

		
		<content type="html" xml:base="https://forum.eggheads.org/viewtopic.php?p=11977#p11977"><![CDATA[
Rather true.<p>Statistics: Posted by <a href="https://forum.eggheads.org/memberlist.php?mode=viewprofile&amp;u=2">ppslim</a> — Mon Oct 14, 2002 11:29 am</p><hr />
]]></content>
	</entry>
		<entry>
		<author><name><![CDATA[strikelight]]></name></author>
		<updated>2002-10-14T11:22:16-04:00</updated>

		<published>2002-10-14T11:22:16-04:00</published>
		<id>https://forum.eggheads.org/viewtopic.php?p=11975#p11975</id>
		<link href="https://forum.eggheads.org/viewtopic.php?p=11975#p11975"/>
		<title type="html"><![CDATA[random number script]]></title>

		
		<content type="html" xml:base="https://forum.eggheads.org/viewtopic.php?p=11975#p11975"><![CDATA[
<blockquote class="uncited"><div>/me pulls out his WHIP<br><div class="codebox"><p>Code: </p><pre><code># Define the scriptproc display:randnum {nick uh hand chan arg} {  # split the incoming var, for easier reading  set coup [split $arg]  #get a random number, using formular RAND = UPPER - (LOWER + 1)  set rand [rand [expr [lindex $coup 1] - [expr [lindex $coup 0] + 1]]]  #Now add LOWER + 1 on to the random number  set rand [expr $rand + [expr [lindex $coup 0] + 1]]  #print it to channel  puthelp "PRIVMSG $chan :Random $rand"}#bind the commandbind pub - "!random" display:randnum</code></pre></div>EG "!random 3 70"<br><br>Will prduce a random number between 3 and 70, excluding 3 and 70.</div></blockquote>And EG "!random [die] now" will cause his bot to die.  <img class="smilies" src="https://forum.eggheads.org/images/smilies/icon_surprised.gif" width="15" height="15" alt=":o" title="Surprised"><p>Statistics: Posted by <a href="https://forum.eggheads.org/memberlist.php?mode=viewprofile&amp;u=2005">strikelight</a> — Mon Oct 14, 2002 11:22 am</p><hr />
]]></content>
	</entry>
		<entry>
		<author><name><![CDATA[ppslim]]></name></author>
		<updated>2002-10-14T11:16:20-04:00</updated>

		<published>2002-10-14T11:16:20-04:00</published>
		<id>https://forum.eggheads.org/viewtopic.php?p=11974#p11974</id>
		<link href="https://forum.eggheads.org/viewtopic.php?p=11974#p11974"/>
		<title type="html"><![CDATA[random number script]]></title>

		
		<content type="html" xml:base="https://forum.eggheads.org/viewtopic.php?p=11974#p11974"><![CDATA[
/me pulls out his WHIP<br><div class="codebox"><p>Code: </p><pre><code># Define the scriptproc display:randnum {nick uh hand chan arg} {  # split the incoming var, for easier reading  set coup [split $arg]  #get a random number, using formular RAND = UPPER - (LOWER + 1)  set rand [rand [expr [lindex $coup 1] - [expr [lindex $coup 0] + 1]]]  #Now add LOWER + 1 on to the random number  set rand [expr $rand + [expr [lindex $coup 0] + 1]]  #print it to channel  puthelp "PRIVMSG $chan :Random $rand"}#bind the commandbind pub - "!random" display:randnum</code></pre></div>EG "!random 3 70"<br><br>Will prduce a random number between 3 and 70, excluding 3 and 70.<p>Statistics: Posted by <a href="https://forum.eggheads.org/memberlist.php?mode=viewprofile&amp;u=2">ppslim</a> — Mon Oct 14, 2002 11:16 am</p><hr />
]]></content>
	</entry>
		<entry>
		<author><name><![CDATA[strikelight]]></name></author>
		<updated>2002-10-14T11:15:55-04:00</updated>

		<published>2002-10-14T11:15:55-04:00</published>
		<id>https://forum.eggheads.org/viewtopic.php?p=11973#p11973</id>
		<link href="https://forum.eggheads.org/viewtopic.php?p=11973#p11973"/>
		<title type="html"><![CDATA[Re: randomnumber script]]></title>

		
		<content type="html" xml:base="https://forum.eggheads.org/viewtopic.php?p=11973#p11973"><![CDATA[
<blockquote class="uncited"><div>Can somone build me a script that give me an randomnumber?<br>when I type !random 3 70 it display me a random number between 3 and 70<br><br>When you can build me one i be your slave  <img class="smilies" src="https://forum.eggheads.org/images/smilies/icon_biggrin.gif" width="15" height="15" alt=":D" title="Very Happy"></div></blockquote><div class="codebox"><p>Code: </p><pre><code>bind pub - !random shins_randproc shins_rand {nick uhost hand chan text} {  set range1 [lindex [split $text] 0]  set range2 [lindex [split $text] 1]  set range1check [string trim $range1 "0123456789"]  set range2check [string trim $range2 "0123456789"]  if {($range1 == "") || ($range2 == "") || ($range1check != "") || ($range2check != "")} {    puthelp "PRIVMSG $chan :Usage: !random &lt;min range&gt; &lt;max range&gt;"    return  }  set randnum [expr [rand [expr ($range2 + 1) - $range1]] + $range1]  puthelp "PRIVMSG $chan :Your number is: $randnum"}</code></pre></div>This is untested code.. but you get the idea..<p>Statistics: Posted by <a href="https://forum.eggheads.org/memberlist.php?mode=viewprofile&amp;u=2005">strikelight</a> — Mon Oct 14, 2002 11:15 am</p><hr />
]]></content>
	</entry>
		<entry>
		<author><name><![CDATA[Anonymous]]></name></author>
		<updated>2002-10-14T10:59:25-04:00</updated>

		<published>2002-10-14T10:59:25-04:00</published>
		<id>https://forum.eggheads.org/viewtopic.php?p=11971#p11971</id>
		<link href="https://forum.eggheads.org/viewtopic.php?p=11971#p11971"/>
		<title type="html"><![CDATA[random number script]]></title>

		
		<content type="html" xml:base="https://forum.eggheads.org/viewtopic.php?p=11971#p11971"><![CDATA[
Can somone build me a script that give me a random number?<br>when I type !random 3 70 it display me a random number between 3 and 70<br><br>When you can build me one i be your slave  <img class="smilies" src="https://forum.eggheads.org/images/smilies/icon_biggrin.gif" width="15" height="15" alt=":D" title="Very Happy"><p>Statistics: Posted by Guest — Mon Oct 14, 2002 10:59 am</p><hr />
]]></content>
	</entry>
	</feed>
