<?xml version="1.0" encoding="utf-8" ?><rss version="2.0" xml:base="https://www.webmaster-forums.net/crss/node/1018247" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title></title>
    <link>https://www.webmaster-forums.net/crss/node/1018247</link>
    <description></description>
    <language>en</language>
          <item>
    <title></title>
    <link>https://www.webmaster-forums.net/server-side-scripting/random-number-generator#comment-1107199</link>
    <description> &lt;p&gt;The easiest thing for you to do would be to place the above sub somewhere WITHIN your current program. That way you can just call it as you would call any other sub using &lt;strong&gt;&amp;amp;generate_random_number(1000);&lt;/strong&gt; but if you put this in a seperate program then you will need to &#039;require&#039; or &#039;use&#039; it in at the beginning of your program which basically means more work on your part.&lt;/p&gt;
&lt;p&gt;If you&#039;re still having difficultes, send me the script to &lt;a href=&quot;mailto:wil@stephens.org&quot; class=&quot;bb-email&quot;&gt;wil@stephens.org&lt;/a&gt; and I can make the neccessary ammendmendts.&lt;/p&gt;
&lt;p&gt;Cheers&lt;/p&gt;
 </description>
     <pubDate>Thu, 18 Apr 2002 08:22:22 +0000</pubDate>
 <dc:creator>Wil</dc:creator>
 <guid isPermaLink="false">comment 1107199 at https://www.webmaster-forums.net</guid>
  </item>
  <item>
    <title></title>
    <link>https://www.webmaster-forums.net/server-side-scripting/random-number-generator#comment-1107184</link>
    <description> &lt;p&gt;i&#039;m getting confused...can i create this as a .pl file...and then call it up WITHIN the program?&lt;/p&gt;
&lt;p&gt;i think i have everything else straight&lt;/p&gt;
 </description>
     <pubDate>Thu, 18 Apr 2002 01:38:26 +0000</pubDate>
 <dc:creator>brady.k</dc:creator>
 <guid isPermaLink="false">comment 1107184 at https://www.webmaster-forums.net</guid>
  </item>
  <item>
    <title></title>
    <link>https://www.webmaster-forums.net/server-side-scripting/random-number-generator#comment-1107120</link>
    <description> &lt;p&gt;You can just place the sub&lt;/p&gt;
&lt;p&gt;&lt;div class=&quot;codeblock&quot;&gt;&lt;code&gt;sub generate_random_number {&lt;br /&gt;&lt;br /&gt;	my $high = $_;&lt;br /&gt;&lt;br /&gt;	my $rand_no = rand($high);&lt;br /&gt;&lt;br /&gt;	return $rand_no;&lt;br /&gt;&lt;br /&gt;}&lt;/code&gt;&lt;/div&gt;&#039;&lt;/p&gt;
&lt;p&gt;within your program. You would call it by calling &lt;strong&gt; &amp;amp;generate_random_number(1000);&lt;/strong&gt; anywhere in your program which will return a random number into &lt;strong&gt;$rand_no&lt;/strong&gt;.&lt;/p&gt;
&lt;p&gt;Is this what you&#039;re looking for?&lt;/p&gt;
 </description>
     <pubDate>Wed, 17 Apr 2002 08:39:12 +0000</pubDate>
 <dc:creator>Wil</dc:creator>
 <guid isPermaLink="false">comment 1107120 at https://www.webmaster-forums.net</guid>
  </item>
  <item>
    <title></title>
    <link>https://www.webmaster-forums.net/server-side-scripting/random-number-generator#comment-1107070</link>
    <description> &lt;p&gt;The function can go in the same file.  But I *think* that the function must be defined before it is called (so just put it as close to the top of the script as you can).&lt;/p&gt;
&lt;p&gt;I forgot about sprintf().  That POSIX module is exactly what I was looking for. Thanks Wil!&lt;/p&gt;
 </description>
     <pubDate>Tue, 16 Apr 2002 20:20:22 +0000</pubDate>
 <dc:creator>Mark Hensler</dc:creator>
 <guid isPermaLink="false">comment 1107070 at https://www.webmaster-forums.net</guid>
  </item>
  <item>
    <title></title>
    <link>https://www.webmaster-forums.net/server-side-scripting/random-number-generator#comment-1107057</link>
    <description> &lt;p&gt;ahh...i&#039;m so bad at this...one more&lt;br /&gt;
does the code go within the program or as a separate file (such as rand_number.pl)&lt;/p&gt;
&lt;p&gt;thanks again, pardon my thickness&lt;/p&gt;
 </description>
     <pubDate>Tue, 16 Apr 2002 18:52:50 +0000</pubDate>
 <dc:creator>brady.k</dc:creator>
 <guid isPermaLink="false">comment 1107057 at https://www.webmaster-forums.net</guid>
  </item>
  <item>
    <title></title>
    <link>https://www.webmaster-forums.net/server-side-scripting/random-number-generator#comment-1107055</link>
    <description> &lt;p&gt;ok...two more questions...&lt;br /&gt;
#1- do i put the #!/usr/local/bin/perl stuff if front?&lt;br /&gt;
#2- do i put the number 1000 in the _ ?&lt;br /&gt;
thanks&lt;/p&gt;
 </description>
     <pubDate>Tue, 16 Apr 2002 18:49:05 +0000</pubDate>
 <dc:creator>brady.k</dc:creator>
 <guid isPermaLink="false">comment 1107055 at https://www.webmaster-forums.net</guid>
  </item>
  <item>
    <title></title>
    <link>https://www.webmaster-forums.net/server-side-scripting/random-number-generator#comment-1106999</link>
    <description> &lt;blockquote class=&quot;bb-quote-body&quot;&gt;&lt;p&gt;Quote: &lt;em&gt;Originally posted by Mark Hensler &lt;/em&gt;&lt;br /&gt;
&lt;strong&gt;&quot;fractional number&quot; ... Is the return data type a float?  If so, how do you make it a whole number?  I didn&#039;t see a floor() or round() function (looked &lt;a href=&quot;http://www.perldoc.com/perl5.6.1/pod/perlfunc.html&quot; class=&quot;bb-url&quot;&gt;here&lt;/a&gt;). &lt;/strong&gt;&lt;/p&gt;&lt;/blockquote&gt;
&lt;p&gt;Mark&lt;/p&gt;
&lt;p&gt;Yes.&lt;/p&gt;
&lt;p&gt;For rounding, you have several options: &lt;/p&gt;
&lt;p&gt;&lt;strong&gt;int&lt;/strong&gt;, which returns the integer portion of an expression. This is probably not what you&#039;re looking for, though.&lt;br /&gt;
&lt;strong&gt;sprintf&lt;/strong&gt;, which lets you format your number exactly the way you like it. Remember, there&#039;s no real difference betwen string and number variables in perl.&lt;br /&gt;
&lt;strong&gt;POSIX::ceil&lt;/strong&gt; or &lt;strong&gt;POSIX::floor&lt;/strong&gt;, which are the equivalent of ceil and floor in C. &lt;/p&gt;
&lt;p&gt;See also: [URL=http://www.perldoc.com/perl5.6.1/pod/perlfaq4.html#Does-Perl-have-a-round()-function---What-about-ceil()-and-floor()---Trig-functions-]Does perl have a round function? What about ceil() and floor()? Trig functions?[/URL] &lt;/p&gt;
&lt;p&gt;Hope this helps&lt;/p&gt;
 </description>
     <pubDate>Tue, 16 Apr 2002 10:14:14 +0000</pubDate>
 <dc:creator>Wil</dc:creator>
 <guid isPermaLink="false">comment 1106999 at https://www.webmaster-forums.net</guid>
  </item>
  <item>
    <title></title>
    <link>https://www.webmaster-forums.net/server-side-scripting/random-number-generator#comment-1106996</link>
    <description> &lt;p&gt;Eskater05,&lt;/p&gt;
&lt;p&gt;If you wanted this inside a program then I&#039;d put it into a sub, where you can pass an argument to it - the highest number randomly returned sounds a good one in your case.&lt;/p&gt;
&lt;p&gt;&lt;div class=&quot;codeblock&quot;&gt;&lt;code&gt;sub generate_random_number {&lt;br /&gt;&lt;br /&gt;	my $high = $_;&lt;br /&gt;&lt;br /&gt;	my $rand_no = rand($high);&lt;br /&gt;&lt;br /&gt;	return $rand_no;&lt;br /&gt;&lt;br /&gt;}&lt;/code&gt;&lt;/div&gt;&#039;&lt;br /&gt;
You would then call this within your program using:&lt;/p&gt;
&lt;p&gt;&lt;div class=&quot;codeblock&quot;&gt;&lt;code&gt;&amp;amp;generate_random_number(1000);&lt;/code&gt;&lt;/div&gt;&#039;&lt;br /&gt;
In the above usage example, you want the highest possible random number to be 1000.&lt;/p&gt;
&lt;p&gt;Calling your sub will return a random number into $rand_no for you to use within your script (to call your random image, for example).&lt;/p&gt;
 </description>
     <pubDate>Tue, 16 Apr 2002 09:31:38 +0000</pubDate>
 <dc:creator>Wil</dc:creator>
 <guid isPermaLink="false">comment 1106996 at https://www.webmaster-forums.net</guid>
  </item>
  <item>
    <title></title>
    <link>https://www.webmaster-forums.net/server-side-scripting/random-number-generator#comment-1106983</link>
    <description> &lt;p&gt;yea...what about a whole number...does it auto pic a whole number?&lt;br /&gt;
also...what if this is to be used in a program...and i dont want to print it...Example:&lt;br /&gt;
1- Picks a Random number&lt;br /&gt;
2- That number then is filed by a program, which then chooses an image based upon that number&lt;/p&gt;
 </description>
     <pubDate>Mon, 15 Apr 2002 23:44:21 +0000</pubDate>
 <dc:creator>brady.k</dc:creator>
 <guid isPermaLink="false">comment 1106983 at https://www.webmaster-forums.net</guid>
  </item>
  <item>
    <title></title>
    <link>https://www.webmaster-forums.net/server-side-scripting/random-number-generator#comment-1106982</link>
    <description> &lt;p&gt;&quot;fractional number&quot; ... Is the return data type a float?  If so, how do you make it a whole number?  I didn&#039;t see a floor() or round() function (looked &lt;a href=&quot;http://www.perldoc.com/perl5.6.1/pod/perlfunc.html&quot; class=&quot;bb-url&quot;&gt;here&lt;/a&gt;).&lt;/p&gt;
 </description>
     <pubDate>Mon, 15 Apr 2002 22:22:56 +0000</pubDate>
 <dc:creator>Mark Hensler</dc:creator>
 <guid isPermaLink="false">comment 1106982 at https://www.webmaster-forums.net</guid>
  </item>
  </channel>
</rss>
