<?xml version="1.0" encoding="utf-8"?>
<rss version="2.0">
  <channel>
    <title>'Putting the result of int(rnd( into a variable.' Thread RSS Feed</title>
    <link>http://www.programmersheaven.com/</link>
    <description>Contains the latest posts from the thread 'Putting the result of int(rnd( into a variable.' posted on the 'Basic' forum at Programmer's Heaven.</description>
    <language>en</language>
    <copyright>Copyright 2013 Programmers Heaven</copyright>
    <pubDate>Fri, 17 May 2013 22:33:35 -0700</pubDate>
    <lastBuildDate>Fri, 17 May 2013 22:33:35 -0700</lastBuildDate>
    <generator>Argotic Syndication Framework 2007.3.0.1, http://www.codeplex.com/Argotic</generator>
    <docs>http://www.rssboard.org/rss-specification</docs>
    <ttl>360</ttl>
    <image>
      <url>http://www.programmersheaven.com/images/ph.gif</url>
      <title>Programmers Heaven</title>
      <link>http://www.programmersheaven.com/</link>
      <width>88</width>
      <height>31</height>
    </image>
    <item>
      <title>Putting the result of int(rnd( into a variable.</title>
      <link>http://www.programmersheaven.com/mb/basic/309307/309307/putting-the-result-of-intrnd-into-a-variable/</link>
      <description>&lt;strong&gt;&lt;span style="color: Red;"&gt;This message was edited by Drakonik at  2005-7-18 17:7:9&lt;/span&gt;&lt;/strong&gt;&lt;hr /&gt;&lt;br /&gt;
How do I do the above? just putting int(rnd(1 * 5) + 1 = variable gives me a syntax error message.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;</description>
      <guid isPermaLink="true">http://www.programmersheaven.com/mb/basic/309307/309307/putting-the-result-of-intrnd-into-a-variable/</guid>
      <pubDate>Mon, 18 Jul 2005 17:06:22 -0700</pubDate>
      <category>Basic</category>
    </item>
    <item>
      <title>Re: Putting the result of int(rnd( into a variable.</title>
      <link>http://www.programmersheaven.com/mb/basic/309307/309536/re-putting-the-result-of-intrnd-into-a-variable/#309536</link>
      <description>&lt;strong&gt;&lt;span style="color: Red;"&gt;This message was edited by IDK at  2005-7-20 11:2:15&lt;/span&gt;&lt;/strong&gt;&lt;hr /&gt;&lt;br /&gt;
: How do I do the above? just putting int(rnd(1 * 5) + 1 = variable gives me a syntax error message.&lt;br /&gt;
: &lt;br /&gt;
: &lt;br /&gt;
: &lt;br /&gt;
First, the left side of the statement&lt;br /&gt;
has to be a single variable, not the&lt;br /&gt;
right. Second, you'll have to end the&lt;br /&gt;
pharantase. Last, 1 * 5 = 5, you're&lt;br /&gt;
just making it more complicated.&lt;br /&gt;
&lt;br /&gt;
This is how it should look like:&lt;br /&gt;
variable = int(rnd(5)) + 1&lt;br /&gt;
&lt;br /&gt;
Edit:&lt;br /&gt;
Another thing I realised, is that this&lt;br /&gt;
way you'll get a number the number's&lt;br /&gt;
2,3,4,5,6. Is this what you wanted?&lt;br /&gt;
Don't you want the numbers 1,2,3,4,5?&lt;br /&gt;
&lt;br /&gt;
&lt;strong&gt;Niklas Ulvinge&lt;/strong&gt; &lt;span style="color: White;"&gt;aka &lt;strong&gt;IDK&lt;/strong&gt;&lt;/span&gt;&lt;br /&gt;</description>
      <guid isPermaLink="true">http://www.programmersheaven.com/mb/basic/309307/309536/re-putting-the-result-of-intrnd-into-a-variable/#309536</guid>
      <pubDate>Wed, 20 Jul 2005 10:57:37 -0700</pubDate>
      <category>Basic</category>
    </item>
    <item>
      <title>Re: Putting the result of int(rnd( into a variable.</title>
      <link>http://www.programmersheaven.com/mb/basic/309307/309541/re-putting-the-result-of-intrnd-into-a-variable/#309541</link>
      <description>: &lt;strong&gt;&lt;span style="color: Red;"&gt;This message was edited by IDK at  2005-7-20 11:2:15&lt;/span&gt;&lt;/strong&gt;&lt;hr /&gt;&lt;br /&gt;
: : How do I do the above? just putting int(rnd(1 * 5) + 1 = variable gives me a syntax error message.&lt;br /&gt;
: : &lt;br /&gt;
: : &lt;br /&gt;
: : &lt;br /&gt;
: First, the left side of the statement&lt;br /&gt;
: has to be a single variable, not the&lt;br /&gt;
: right. Second, you'll have to end the&lt;br /&gt;
: pharantase. Last, 1 * 5 = 5, you're&lt;br /&gt;
: just making it more complicated.&lt;br /&gt;
: &lt;br /&gt;
: This is how it should look like:&lt;br /&gt;
: variable = int(rnd(5)) + 1&lt;br /&gt;
: &lt;br /&gt;
: Edit:&lt;br /&gt;
: Another thing I realised, is that this&lt;br /&gt;
: way you'll get a number the number's&lt;br /&gt;
: 2,3,4,5,6. Is this what you wanted?&lt;br /&gt;
: Don't you want the numbers 1,2,3,4,5?&lt;br /&gt;
: &lt;br /&gt;
: &lt;strong&gt;Niklas Ulvinge&lt;/strong&gt; &lt;span style="color: White;"&gt;aka &lt;strong&gt;IDK&lt;/strong&gt;&lt;/span&gt;&lt;br /&gt;
: &lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Well, I got the result into a variable. I had copied the code almost verbatim from the book I learned Liberty BASIC from. I think I'm fun with a tiny variation from what I expected. And, it's just for a game. An insignificant, no-longer-remember game, which I started trying to code months ago.&lt;br /&gt;</description>
      <guid isPermaLink="true">http://www.programmersheaven.com/mb/basic/309307/309541/re-putting-the-result-of-intrnd-into-a-variable/#309541</guid>
      <pubDate>Wed, 20 Jul 2005 12:25:41 -0700</pubDate>
      <category>Basic</category>
    </item>
    <item>
      <title>Re: Putting the result of int(rnd( into a variable.</title>
      <link>http://www.programmersheaven.com/mb/basic/309307/309968/re-putting-the-result-of-intrnd-into-a-variable/#309968</link>
      <description>: &lt;strong&gt;&lt;span style="color: Red;"&gt;This message was edited by IDK at  2005-7-20 11:2:15&lt;/span&gt;&lt;/strong&gt;&lt;hr /&gt;&lt;br /&gt;
: : How do I do the above? just putting int(rnd(1 * 5) + 1 = variable gives me a syntax error message.&lt;br /&gt;
: : &lt;br /&gt;
: : &lt;br /&gt;
: : &lt;br /&gt;
: First, the left side of the statement&lt;br /&gt;
: has to be a single variable, not the&lt;br /&gt;
: right. Second, you'll have to end the&lt;br /&gt;
: pharantase. Last, 1 * 5 = 5, you're&lt;br /&gt;
: just making it more complicated.&lt;br /&gt;
: &lt;br /&gt;
: This is how it should look like:&lt;br /&gt;
: variable = int(rnd(5)) + 1&lt;br /&gt;
: &lt;br /&gt;
: Edit:&lt;br /&gt;
: Another thing I realised, is that this&lt;br /&gt;
: way you'll get a number the number's&lt;br /&gt;
: 2,3,4,5,6. Is this what you wanted?&lt;br /&gt;
: Don't you want the numbers 1,2,3,4,5?&lt;br /&gt;
: &lt;br /&gt;
: &lt;strong&gt;Niklas Ulvinge&lt;/strong&gt; &lt;span style="color: White;"&gt;aka &lt;strong&gt;IDK&lt;/strong&gt;&lt;/span&gt;&lt;br /&gt;
: &lt;br /&gt;
I don't mean to cause any offense to Niklas Ulvinge, but since Rnd returns a random number from 0 to 1, and 0 * 5 = 0, then the +1 is nesecary for 1,2,3,4,5. but you are right, it would return 1,2,3,4,5,and 6, so you want to give it rnd(4)&lt;br /&gt;
the finished syntax: variable = int(rnd(4)) +1&lt;br /&gt;</description>
      <guid isPermaLink="true">http://www.programmersheaven.com/mb/basic/309307/309968/re-putting-the-result-of-intrnd-into-a-variable/#309968</guid>
      <pubDate>Sun, 24 Jul 2005 16:24:19 -0700</pubDate>
      <category>Basic</category>
    </item>
    <item>
      <title>Re: Putting the result of int(rnd( into a variable.</title>
      <link>http://www.programmersheaven.com/mb/basic/309307/310012/re-putting-the-result-of-intrnd-into-a-variable/#310012</link>
      <description>: : &lt;strong&gt;&lt;span style="color: Red;"&gt;This message was edited by IDK at  2005-7-20 11:2:15&lt;/span&gt;&lt;/strong&gt;&lt;hr /&gt;&lt;br /&gt;
: : : How do I do the above? just putting int(rnd(1 * 5) + 1 = variable gives me a syntax error message.&lt;br /&gt;
: : : &lt;br /&gt;
: : : &lt;br /&gt;
: : : &lt;br /&gt;
: : First, the left side of the statement&lt;br /&gt;
: : has to be a single variable, not the&lt;br /&gt;
: : right. Second, you'll have to end the&lt;br /&gt;
: : pharantase. Last, 1 * 5 = 5, you're&lt;br /&gt;
: : just making it more complicated.&lt;br /&gt;
: : &lt;br /&gt;
: : This is how it should look like:&lt;br /&gt;
: : variable = int(rnd(5)) + 1&lt;br /&gt;
: : &lt;br /&gt;
: : Edit:&lt;br /&gt;
: : Another thing I realised, is that this&lt;br /&gt;
: : way you'll get a number the number's&lt;br /&gt;
: : 2,3,4,5,6. Is this what you wanted?&lt;br /&gt;
: : Don't you want the numbers 1,2,3,4,5?&lt;br /&gt;
: : &lt;br /&gt;
: : &lt;strong&gt;Niklas Ulvinge&lt;/strong&gt; &lt;span style="color: White;"&gt;aka &lt;strong&gt;IDK&lt;/strong&gt;&lt;/span&gt;&lt;br /&gt;
: : &lt;br /&gt;
: I don't mean to cause any offense to Niklas Ulvinge, but since Rnd returns a random number from 0 to 1, and 0 * 5 = 0, then the +1 is nesecary for 1,2,3,4,5. but you are right, it would return 1,2,3,4,5,and 6, so you want to give it rnd(4)&lt;br /&gt;
: the finished syntax: variable = int(rnd(4)) +1&lt;br /&gt;
: &lt;br /&gt;
No, your right, it was a long time since I programmed in basic and I&lt;br /&gt;
often mix the funcs, the one I thought of was fix. But it wont return&lt;br /&gt;
6, becouse RND returns a number between 0 and 1, and the propability&lt;br /&gt;
that it will return 1 is almost 0.&lt;br /&gt;
&lt;br /&gt;
Another thing, in qbasic the parameter to rnd is a number that will do&lt;br /&gt;
different things. If it's negative it will return the same number all&lt;br /&gt;
the time, and different things. Youre don't use qbasic so this wont&lt;br /&gt;
bother you.&lt;br /&gt;
&lt;br /&gt;
In QBasic it would look like: INT(RND*5)+1&lt;br /&gt;
The thing's I've said is mostly for qbasic.&lt;br /&gt;
I don't know how your version acts.&lt;br /&gt;
&lt;br /&gt;
&lt;strong&gt;Niklas Ulvinge&lt;/strong&gt; &lt;span style="color: White;"&gt;aka &lt;strong&gt;IDK&lt;/strong&gt;&lt;/span&gt;&lt;br /&gt;
&lt;br /&gt;</description>
      <guid isPermaLink="true">http://www.programmersheaven.com/mb/basic/309307/310012/re-putting-the-result-of-intrnd-into-a-variable/#310012</guid>
      <pubDate>Mon, 25 Jul 2005 02:07:48 -0700</pubDate>
      <category>Basic</category>
    </item>
    <item>
      <title>Re: Putting the result of int(rnd( into a variable.</title>
      <link>http://www.programmersheaven.com/mb/basic/309307/312848/re-putting-the-result-of-intrnd-into-a-variable/#312848</link>
      <description>&lt;strong&gt;&lt;span style="color: Red;"&gt;This message was edited by moneo at  2005-8-20 16:30:41&lt;/span&gt;&lt;/strong&gt;&lt;hr /&gt;&lt;br /&gt;
: &lt;strong&gt;&lt;span style="color: Red;"&gt;This message was edited by Drakonik at  2005-7-18 17:7:9&lt;/span&gt;&lt;/strong&gt;&lt;hr /&gt;&lt;br /&gt;
: How do I do the above? just putting int(rnd(1 * 5) + 1 = variable gives me a syntax error message.&lt;br /&gt;
: &lt;br /&gt;
: &lt;br /&gt;
: &lt;br /&gt;
In order not to get mixed up regarding the range (from-to) of random numbers that the RND will produce, I suggest using the following standard function:&lt;br /&gt;
&lt;br /&gt;
DECLARE FUNCTION RandInt% (lower, Upper)&lt;br /&gt;
RANDOMIZE TIMER&lt;br /&gt;
&lt;br /&gt;
' ======================= RandInt% =============================&lt;br /&gt;
' Returns a random integer greater than or equal to the Lower parameter&lt;br /&gt;
' and less than or equal to the Upper parameter.&lt;br /&gt;
' ==================================================
============&lt;br /&gt;
&lt;br /&gt;
FUNCTION RandInt% (Lower, Upper) STATIC&lt;br /&gt;
   RandInt% = INT(RND * (Upper - Lower + 1)) + Lower&lt;br /&gt;
END FUNCTION&lt;br /&gt;
&lt;br /&gt;
*****&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;</description>
      <guid isPermaLink="true">http://www.programmersheaven.com/mb/basic/309307/312848/re-putting-the-result-of-intrnd-into-a-variable/#312848</guid>
      <pubDate>Sat, 20 Aug 2005 16:23:27 -0700</pubDate>
      <category>Basic</category>
    </item>
  </channel>
</rss>